-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confetti on initial load #16
Comments
Hooks to the rescue :-) const Yay : React.FC<{}> = () => {
const trigger = useBoolean(false);
useEffect(() => {
setTimeout(trigger.setTrue, 300);
//eslint-disable-next-line
}, [])
return (<Confetti active={trigger.value} config={confettiConfig} />);
} |
Is there way to do this without hooks? |
@AdiBev you could put it inside this.state = {
active: false
}
componentDidMount() {
setTimeout(() => {
this.setState({ active: true });
}, 300);
}
... You probably don't even need the timeout if you use it within a |
Alternatively, we can drop the const Component = () => {
const [active, setActive] = useState(false);
return (
<Confetti
ref={() => { setActive(true) }}
active={active}
config={confettiConfig}
/>);
} |
This is the first thing I ran in as well. I kind of expected |
Hey,
I was able to get it to work upon a state change. Wondering if there is a way to make the confetti appear when a component loads initially without any state change. I tried setting the
active
attribute totrue
but that didn't work. Help will be appreciated!The text was updated successfully, but these errors were encountered: