How to integrate flip cards into React app

Like any developer, I always try to add interesting animations to my projects. With React.js it can be very easy.

I want to add into my project flip cards animation.

And I want to show you how to do that based on my project “Rise and Shine”.

The main page of project looks like:

And I want to flip cards, when I click on button “Click to flip”.

Let’s do it:

npm install — save react-card-flip

2. Then import this library into your component where you want to use it:

3. Then you should to create a function, which will control this action. In my case there is a functional component, and I need to set state, that will allows me to control flipping cards. So for set state I used hooks useState.

4. After this I set the ReactCadrFlip component and inside this component I created two different div: one for the front side and one for the back side:

5. Inside each div I created a button on click which calls our controlling action HandleClick. So, that it. Very easy, so when I click on button “Click to flip” I can see the other side of my cards:

And it works to each card.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store