-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Destroy confetti instance on unmount
fix #47
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useState } from 'react' | ||
import { storiesOf } from '@storybook/react' | ||
|
||
import ReactConfetti from '../src/ReactConfetti' | ||
|
||
const Toggler = ({ children }) => { | ||
const [isVisible, setVisible] = useState(true) | ||
const handleClick = () => { | ||
setVisible(!isVisible) | ||
} | ||
return ( | ||
<div> | ||
{isVisible && children} | ||
<div style={{ position: 'absolute', top: 10, left: 10 }}> | ||
<button onClick={handleClick}> | ||
Toggle | ||
</button> | ||
<aside style={{ marginTop: '2rem' }}> | ||
This is just to test that the confetti is cleaned up properly when the component is unmounted. | ||
</aside> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
storiesOf('Tests', module) | ||
.add('Cleanup on mount', () => ( | ||
<Toggler> | ||
<ReactConfetti style={{ zIndex: 0 }} /> | ||
</Toggler> | ||
)) |