You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I'm looking through the source here, and noticed something you may want to consider.
When you call useDebouncedCallback in a server environment using ReactDOM.renderToString, no async calls to requestAnimationFrame or setTimeout should occur. React will avoid calling useEffect mounting code to enable this case.
Unforunately, this hook is calling setTimeout in render scope. This should be refactored to only perform side effects like enquing async callbacks in useEffect, where you can avoid them in server scenarios and safely cancel them in client scenarios.
Describe the bug
I'm looking through the source here, and noticed something you may want to consider.
When you call
useDebouncedCallback
in a server environment usingReactDOM.renderToString
, no async calls torequestAnimationFrame
orsetTimeout
should occur. React will avoid callinguseEffect
mounting code to enable this case.Unforunately, this hook is calling setTimeout in render scope. This should be refactored to only perform side effects like enquing async callbacks in
useEffect
, where you can avoid them in server scenarios and safely cancel them in client scenarios.To Reproduce
render this to a string in a browser using
React.renderToString
, and see the message in the console 1 second later.https://codesandbox.io/s/proud-lake-vjwqh5?file=/src/index.tsx
Expected behavior
No message in the console
use-debounce version:
reading the github code, but also 8.0.3 in the sandbox.
The text was updated successfully, but these errors were encountered: