DEV Community

Cover image for Day 3 of #100DaysOfCode: Create transitions with React-transition-group
Jen-Hsuan Hsieh
Jen-Hsuan Hsieh

Posted on • Edited on

2 1

Day 3 of #100DaysOfCode: Create transitions with React-transition-group

Introduction

It looks better if we add transitions when adding or removing items on the page. Today I tried to use React-transition-group for transitions.

Steps to use React-transition-group

  1. Install package or include CDN
https://cdnjs.cloudflare.com/ajax/libs/react-transition-group/4.3.0/react-transition-group.js
Enter fullscreen mode Exit fullscreen mode

2.Import package to the React Component

const { CSSTransition, TransitionGroup } = ReactTransitionGroup;
Enter fullscreen mode Exit fullscreen mode

3.Wrap the component with TransitionGroup and CSSTransition

return (
        <div className="container menu-container">
            <div className="row">
                products.map(product => (
                    <TransitionGroup>
                        <CSSTransition key={product.id} timeout={500} classNames="item">
                            <MenuItem product = {product} />
                        </CSSTransition>
                    </TransitionGroup>
                ))}
             </div>
        </div>
)
Enter fullscreen mode Exit fullscreen mode

That's it!

Implementations

Articles

There are some of my articles. Feel free to check if you like!

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs