Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paigen11/9602e87f8f7d5943b713b521989503b7 to your computer and use it in GitHub Desktop.
Save paigen11/9602e87f8f7d5943b713b521989503b7 to your computer and use it in GitHub Desktop.
Sample JavaScript code of React Transition Group's TransitionGroup component
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)
)
}
>
&times;
</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