Skip to content
Advertisement

Tag: react-context

How to prevent useEffect() run twice after running a function in context consumer and prevent useContext() to re-render

I’m learned that React will re-render after state changed e.g. setState from useState(), calling the function or variable from useContext() variable. But now I’m don’t understand that why I get the ESLint warning call the context function inside the useCallback() without dependency in the list. If I put the dependency in the list, useCallback() will be re-rendered and useEffect() dependency

Why am I getting undefined prop?

Below is my Header component in react: I have used ContextAPI for efficient state Management.CryptoState is used for this purpose.I have imported the state in Header and getting the necessary props using object-destructuring. Below is my Context-file: I am getting this error in Header component:Header.js:8 Uncaught TypeError: Cannot destructure property ‘currency’ of ‘(0 , _CryptoContext__WEBPACK_IMPORTED_MODULE_1__.CryptoState)(…)’ as it is undefined. Answer

Advertisement