Skip to content
Advertisement

Tag: react-hooks

Why is useState not triggering re-render?

I’ve initialized a state that is an array, and when I update it my component does not re-render. Here is a minimal proof-of-concept: Based on this code, it seems that the input should contain the number 0 to start, and any time it is changed, the state should change too. After entering “02” in the input, the App component does

useMemo vs. useEffect + useState

Are there any benefits in using useMemo (e.g. for an intensive function call) instead of using a combination of useEffect and useState? Here are two custom hooks that work exactly the same on first sight, besides useMemo’s return value being null on the first render: useEffect & useState useMemo Both calculate the result each time their parameter someNumber changes, where

react useEffect comparing objects

I am using react useEffect hooks and checking if an object has changed and only then run the hook again. My code looks like this. Unfortunately it keeps running as the objects are not being recognised as being the same. I believe the following is an example of why. Perhaps running JSON.stringify(apiOptions) works? Answer Use apiOptions as state value I’m

Advertisement