Same as React's `useCallback`, but returns a stable reference.
npm install react-use-event-hookuseCallback, but returns a stable reference.This library is a user-land implementation of the useEvent hook, proposed in this RFC.
``sh`
npm install react-use-event-hook
You can wrap any event handler into useEvent.
`js
import useEvent from 'react-use-event-hook';
function Chat() {
const [text, setText] = useState('');
const onClick = useEvent(() => {
sendMessage(text);
});
return
}
`
The code inside useEvent “sees” the props/state values at the time of the call.
The returned function has a stable identity even if the props/state it references change.
There is no dependency array.