npm.io
0.0.6 • Published 4 years ago

babel-plugin-react-no-hook-dependency

Licence
MIT
Version
0.0.6
Deps
2
Size
41 kB
Vulns
0
Weekly
0

babel-plugin-react-no-hook-dependency

A babel plugin to automagically add the deps array to your hook calls.

Node.js CI

Examples

Adding dependency array to useMemo call

In
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  });
  return <></>;
}
Out
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  }, [state]);
  return <></>;
}
Leaving hook invocation untouched when a deps array is provided
In
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  }, [state]);
  return <></>;
}
Out
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  }, [state]);
  return <></>;
}
Using a hook with no deps array
In
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  }, undefined);
  return <></>;
}
Out
function App() {
  const [state, setState] = useState(0);
  const toDisplay = useMemo(() => {
    return state;
  });
  return <></>;
}

Install

Using NPM:

npm install --save-dev babel-plugin-react-no-hook-dependency

Using yarn:

yarn add babel-plugin-react-no-hook-dependency --dev