useWhy icon indicating copy to clipboard operation
useWhy copied to clipboard

React hook to answer "Why did this effect happen?"

useWhy

Watch React hook dependencies and report which dependency caused the hook to fire.

Usage

import useWhy from 'usewhy';

function YourComponent(props) {
  const [name, setName] = useState("");
  useEffect(
    () => {
      console.log('hello world!', name);
    },
    useWhy([name])
  );

  return (
    <input type="text" onChange={(e) => setState(e.target.value);} />
  )
}