useState和useReducer区别

useState本质上是简易版的useReducer

在mount阶段,两者的区别为:

  • useState的lastRender就是basicStateReducer
  • useReducer的lastRender就传入的reducer

所以useState可以视为reducer参数是basicStateReducer的useReducer

在update阶段:

updateState内部调用的就是updateReducer,传入的reducer仍然是basicStateReducer

你可能感兴趣的:(React,js,前端,前端,javascript,开发语言)