无法使用 useRef 作为 componentDidUpdate 替代品

2024-07-03

Error

未捕获的类型错误:Object(...) 不是函数

import { useSelector, useDispatch, useRef } from 'react-redux'

const mounted = useRef();

    useEffect(() => {
        console.log('mounted', mounted)
        console.log('useEffect props:', props)

我有一个功能组件,并试图利用钩子来使用 componentDidUpdate,在我的 onSubmit 函数中,我触发了一个调用和 API 的调度,我需要查看该 API 的结果有效负载是什么,它存储在 redux 中。但我收到上面的错误?

我发现这个答案说使用 useRef相当于使用 React hooks 的 componentDidUpdate https://stackoverflow.com/questions/53255951/equivalent-to-componentdidupdate-using-react-hooks


useRef 是一个 React 钩子。改成:

import React, { useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 useRef 作为 componentDidUpdate 替代品 的相关文章

随机推荐