不能使用 useRef 作为 componentDidUpdate 替换 [英] Can't use useRef as componentDidUpdate replacement
本文介绍了不能使用 useRef 作为 componentDidUpdate 替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误
未捕获的类型错误:Object(...) 不是函数
Uncaught TypeError: Object(...) is not a function
import { useSelector, useDispatch, useRef } from 'react-redux'
const mounted = useRef();
useEffect(() => {
console.log('mounted', mounted)
console.log('useEffect props:', props)
我有一个功能组件,并试图利用钩子来使用 componentDidUpdate,在我的 onSubmit 函数中,我触发了一个调用和 API 的调度,我需要查看该 API 的结果负载是什么,它存储在还原.但是我得到了上面的错误?
I have a functional component and trying to take advantage of hooks to use componentDidUpdate, in my onSubmit function I fire a dispatch to call and API, and I need to see what is the resulting payload of that API, which is stored in redux. But I get the error above?
我发现这个答案说使用 useRef 相当于使用 React 钩子的 componentDidUpdate一个>
I found this answer which said to use useRef Equivalent to componentDidUpdate using React hooks
推荐答案
useRef 是一个 React 钩子.更改为:
useRef is a React hook. Change to:
import React, { useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
这篇关于不能使用 useRef 作为 componentDidUpdate 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文