useMemo,作为componentWillMount的替代方法

时间:2019-06-15 15:56:06

标签: redux react-hooks redux-react-hook

以前用于加载数据,我在服务器端使用componentWillMount,在客户端使用componentDidMount。为了替换组件类,我想使用useEffect挂钩进行加载。但是useEffect仅适用于客户端。因此,现在我在客户端和服务器端都使用useMemo。 我可以做一个技巧,在服务器端使用useMomo在客户端使用useEffect

我只是想知道专家的意见,这种方法对处理这种情况是好是坏。

这是示例函数组件。

const Home = () => {

    const dispatch = useDispatch()
    useMemo(() => {
        dispatch(load())
    }, [true])
    -------
    -------
}

0 个答案:

没有答案
相关问题