Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-event-callback

volune97kISC0.1.0TypeScript support: included

React hook useEventCallback

react, hooks, useEventCallback, useCallback

readme

React hook useEventCallback

Aimed to be easier to use than useCallback and solve problems raised in this ticket.

useEventCallback doesn't need any dependencies list. The returned function should not be used during rendering.

Example

import useEventCallback from 'use-event-callback';

const Input = () => {
  const [value, setValue] = useState('');
  const onChange = useEventCallback((event) => {
    setValue(event.target.value);  
  });

  return <input value={value} onChange={onChange} />;
}