使用 TypedUseSelectorHook 重写 useSelector
来源:8-10 【redux封装】在函数式组建中使用react-redux

幕布斯8089534
2021-11-21
重写 useSelector 时用 TypedUseSelectorHook 给它加了 RootState 类型,为什么这种写法就可以实现组件复用了呢?
在我看来,这样也还是把类型绑定起来了。
写回答
1回答
-
hello 同学你好。
重写 useSelector 时用 TypedUseSelectorHook 给它加了 RootState 类型以后,我们在使用这个加强版的useSelector以后,它就会自带store中的所有类型,我们就不需要在文件(组件)中引入store了。当我们不再引用store的时候,sotre和组件就解绑了
222024-06-17
相似问题