Quantcast
Channel: Test react forceUpdate custom hook useEffect/useState - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Test react forceUpdate custom hook useEffect/useState

$
0
0

I created a custom hook to force a component to update but I'm having issues figuring out how to write a unit test with jest.

This is the hook


function useForceUpdate(condition) {
  const [, setState] = useState(0);
  const forceUpdate = () => setState(1);
  useEffect(() => {
    if (condition) {
      forceUpdate();
    }
  }, [condition]);
}

export default useForceUpdate;

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>