Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs store.dispatch、useDispatch和useReducer的dispatch之间有什么区别?_Reactjs_Redux - Fatal编程技术网

Reactjs store.dispatch、useDispatch和useReducer的dispatch之间有什么区别?

Reactjs store.dispatch、useDispatch和useReducer的dispatch之间有什么区别?,reactjs,redux,Reactjs,Redux,。。。 我看到所有触发操作,但useReducer dispatch不更新redux状态。正确,useReducer不更新redux存储useReducer是一个常规的react钩子,允许组件以功能性方式应用本地状态更新,类似于Redux(一个非常常见的全局应用程序状态管理库)使用的模式。将useReducer视为Redux的组件状态版本,即应用程序状态 useDispatch是由react redux提供的一个钩子,它使用redux上下文(包含存储/状态),类似于connect高阶组件在包装组

。。。
我看到所有触发操作,但useReducer dispatch不更新redux状态。

正确,
useReducer
不更新redux存储
useReducer
是一个常规的react钩子,允许组件以功能性方式应用本地状态更新,类似于Redux(一个非常常见的全局应用程序状态管理库)使用的模式。将
useReducer
视为Redux的组件状态版本,即应用程序状态

useDispatch
是由
react redux
提供的一个钩子,它使用redux上下文(包含存储/状态),类似于
connect
高阶组件在包装组件时提供的功能。它们都提供了一个
dispatch
功能,用于将操作分派到redux存储

store.dispatch
dispatch
功能


注意:
react redux
connect
HOC使用
redux
bindActionCreators
将分派函数包装(绑定)到
mapDispatchToProps
中定义的动作创建者,就术语而言,
dispatch
不是“高阶函数”。它只是一个由
createStore
返回的函数。它在概念上等同于类上的方法。@markerikson是的,非常正确,从技术上讲,它是来自
redux
bindActionCreators
,它是一个装饰器,返回一个带有
dispatch
的函数,由
mapDispatchToProps
组成动作创建者。
import React, { useReducer } from "react";
import { useDispatch } from "react-redux";
import { createStore } from "redux";

const store = createStore(