Created
April 12, 2020 21:48
-
-
Save paigen11/9602e87f8f7d5943b713b521989503b7 to your computer and use it in GitHub Desktop.
Sample JavaScript code of React Transition Group's TransitionGroup component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ChoresToDo = () => { | |
const [chores, setChores] = useState([ | |
{ id: 1, text: 'Dust' }, | |
{ id: 2, text: 'Polish floors' }, | |
{ id: 3, text: 'Wipe down countertops' } | |
]); | |
return ( | |
<Container> | |
<ListGroup> | |
<TransitionGroup className="todo-list"> | |
{chores.map(({ id, description }) => ( | |
<CSSTransition | |
key={id} | |
timeout={500} | |
classNames="chore" | |
> | |
<ListGroup.Item> | |
<Button | |
className="remove-btn" | |
variant="danger" | |
size="sm" | |
onClick={() => | |
setChores(chores => | |
chores.filter(chore => chore.id !== id) | |
) | |
} | |
> | |
× | |
</Button> | |
{description} | |
</ListGroup.Item> | |
</CSSTransition> | |
))} | |
</TransitionGroup> | |
</ListGroup> | |
</Container> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment