Skip to content

Tag: react-hooks

Wrong React hooks behaviour with event listener

I’m playing around with React Hooks and am facing a problem. It shows the wrong state when I’m trying to console log it using a button handled by event listener. CodeSandbox: https://codesandbox.io/s/lrxw1wr97m Click on ‘Add card’ button 2 times In first card, click on Button1 and see …

Make React useEffect hook not run on initial render

According to the docs: componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render. We can use the new useEffect() hook to simulate componentDidUpdate(), but it seems like useEffect() is being ran after every render, even the first time. How do I get it …