Can't Use UseRef As ComponentDidUpdate Replacement
Error Uncaught TypeError: Object(...) is not a function import { useSelector, useDispatch, useRef } from 'react-redux' const mounted = useRef(); useEffect(() => {
Solution 1:
useRef is a React hook. Change to:
import React, { useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
Solution 2:
You should access your ref using mounted.current
. Since you are not initializing it a value, it will return undefined
.
If you are assigning your ref to a JSX element, you will not be able to access it until the DOM has loaded. In that case, I would suggest using the useLayoutEffect
hook, since it will not run until the DOM has loaded.
Post a Comment for "Can't Use UseRef As ComponentDidUpdate Replacement"