3 ms·
I can call ‘setTimeout’ from the component? I honestly don’t see the issue with your example. I’d use an event handler to work out when something happened. Th
by ddek 6y ago
I can call ‘setTimeout’ from the component?
I honestly don’t see the issue with your example.
I’d use an event handler to work out when something happened. This would set the timeout, and the handle would be stored as a ref. I’d have a use effect hook to clean up the timer, so when the component is unmounted the timeout is cleared.
What’s the issue here?
- 7777fps 6y agoIt's no longer declarative as soon as you've done that though; it's still a break in the declarative paradigm.
- ativzzz 6y agoThe issue is it's not as simple as calling `setTimeout` as soon as your use case becomes more complex. See this great post from Dan Abramov about using setInterval with hooks: https://overreacted.io/making-setinterval-declarative-with-react-hooks/ https://overreacted.io/making-setinterval-declarative-with-r...