Incorporating a prop in keyframe animation with styled components

How should props be properly used within animations: ${styledKeyFrame} ${props.myProps}?

The problem:

import styled from 'styled-components';
const KeyFrameTest = styled.keyframes`
    from { opacity: 0; }
    to { opacity: 1; }
`;

const StyledComponent = styled.div`
 animation: ${KeyFrameTest} 2s 4s ease-in; /* works */
 animation: ${props => `${KeyFrameTest} 2s ${props.delay} ease-in`}; /* ERROR */
 animation: ${props => `${styled.css`{KeyFrameTest}}` 2s ${props.delay} ease-in`}; /* ERROR */
`;

const PureComponent = () => <StyledComponent delay="3s" />;
export default PureComponent;

Answer №1

It seems like the issue arises when attempting to incorporate KeyFrames within the ${props => } syntax.

I am not certain about the specific version of styled-components you have, but I believe the following modification could resolve it;

animation: ${KeyFrameTest} 2s ${props => props.delay} ease-in

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for obtaining the position integer of an item within a PHP array and transferring it from PHP to HTML?

I'm currently working on a function called getTopics() that should not only return the topic but also its position. For instance, when returning "Musical instruments," it should also provide the integer 0 for use in the getFaqs() function. Likewise, r ...

Modifying the value of an animated status bar using the same class but different section

I need the status bars to work individually for each one. It would be great if the buttons also worked accordingly. I have been trying to access the value of "data-bar" without success (the script is able to process the "data-max"). However, the script see ...

how to ensure a consistent property value across all scopes in AngularJS

Here is my perspective <div ng-if="isMultiChoiceQuestion()"> <li class="displayAnswer" ng-repeat="choice in getMultiChoice() track by $index" ng-if="isNotEmpty(choice.text.length)"> <input type= ...

Axios is not properly executing the post request

While attempting to submit data using axios in NodeJS and ReactJS, I encountered the following errors: https://i.sstatic.net/3FM6o.png https://i.sstatic.net/XZ0iS.png Here is the code I used for posting: axios({ method: 'post', url: ...

What is the best way to test react-router Links using Enzyme?

Many similar questions to this have been observed, but they all appear to be outdated or overly complex. In my React component, there is a React Router Link component, structured like this: export default class Home extends Component { ...

What is the process for retrieving information from a JSON document?

When working on my project using Next.js, I encountered an issue with fetching and displaying data from a JSON file named mainMenu. Could someone please guide me on how to correctly implement this? I have shared my code below: function MyApp({ Component, ...

Styling HTML elements for Google custom search API json results: Best practices

I have been working with the Google Custom Search API to retrieve JSON callback results for my project. I have been experimenting with the JSON callback variables based on the recommendations from Google's documentation available here: https://github ...

Using Angular 2+ to make HTTP POST requests and interact with the GDrive API. Implementing resumable file uploads

I am currently facing a challenge with uploading files to Google Drive using Angular 2. I have managed to upload files successfully, but they end up being labeled as "Untitled" without any title. Below is the code snippet I am using for the upload process ...

Is it impossible to style an element within a div tag?

How can I apply styling to a specific div with id="1", which contains class="match"? Here is the code: <div class="col-lg-3"> <div id="1"> <p class="match">Match {this.state.matches[0].id}</p> <div class="tea ...

Issue with the scope of Bootstrap Accordion

Observing that the event triggers on a single Bootstrap accordion can affect all other accordions on the same page, I am wondering if there is a way to isolate this behavior without altering the markup or using $(this). Any suggestions? Check out this exam ...

Sorry, I'm unable to determine the value of 'title' because it is undefined

Here is the code for the "singleCard" component. When passing {{card.title}} and {{card.body}}, an error occurs: **Error in render: "TypeError: Cannot read property 'title' of undefined" found in ---> <SingleCard> at src/components/sing ...

Can you please explain the significance of the code "!!~this.roles.indexOf('*')" within the MEAN.io framework?

One particular line of code can be found in the startup file for the MEAN framework. if (!!~this.roles.indexOf('*')) { This specific line is located within the shouldRender function of the menus.client.service.js file, which resides in the publ ...

Transforming rdl files into pdf with the power of JavaScript

I need assistance converting my rdl report to PDF using Javascript. It would greatly help if I could accomplish this task with just the OpenReport() function to avoid having to convert it into a ppt later on. I am currently working in CRM online. Below is ...

Generating a download link with an expiration feature in node.js or express for both frontend and backend operations

Hello everyone, I'm a beginner here and have recently started working with node.js and express.js. I am looking to implement a download link on my website that expires after a certain time, but I've been struggling with the code for about a week ...

Expand the image background to fit within a div container

Below is the code snippet I am working on: <div id="intro_section_upper" > <%= image_tag("video_background.jpg", :id=>"video_bg") %> <div id="video_table_main" > <table class=" ...

Developing an interface that utilizes the values of an enum as keys

Imagine having an enum called status export enum status { PENDING = 'pending', SUCCESS = 'success', FAIL = 'fail' } This enum is used in multiple places and should not be easily replaced. However, other developers migh ...

Setting a variable equal to user input

When using a jQuery script, the elements for the details are dynamically created inside a jQuery function. However, there seems to be an issue with assigning the value from the variable "startLocation" to the input "detail_startLocation[]". Only the firs ...

Troubleshooting a query problem within a forum built with ReactJS, MySQL, Node.js, and Express

As a junior developer, I am currently working on creating a basic forum using ReactJS, Node.js, Express, and MySQL. In the forum, it is essential for each Topic to have multiple Posts associated with it. I am encountering an issue where the posts are not ...

How should an iterable be sorted in React?

Let's break down the scenario using pseudo code: {this.props.myIterable.map((iterable) => { return ( <div>iterable.somevalue</div> ) }).sort((a,b) => {return b - a}) To clarify, I am iterating over certain props and displaying ...

Sharing FormikProps between components in React: A step-by-step guide

I am struggling to pass the necessary values and props that Formik requires to the component one level up. My approach involves using several small components for various forms, and I need to pass them through a complex component to be able to pass them do ...