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
functionuseEvent(fn,dependencies){constref=useRef(()=>{thrownewError("Cannot call an event handler while rendering.");});useEffect(()=>{ref.current=fn;},[fn, ...dependencies]);returnuseCallback((evn)=>{constfn=ref.current;returnfn(evn);},[ref]);}
functionChat(){const[text,setText]=useState('');// ✅ Always the same function (even if `text` changes)constonClick=useEvent(()=>{sendMessage(text);});return<SendButtononClick={onClick}/>;}
The text was updated successfully, but these errors were encountered:
https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
https://codesandbox.io/embed/react-context-example-df8zoq?fontsize=14&hidenavigation=1&theme=dark
Polyfill
The text was updated successfully, but these errors were encountered: