sanonz / sanonz.github.io

存放博客静态文件的仓库,使用 Hexo 以及博主自己写的一个主题:https://github.com/sanonz/hexo-theme-concise
https://sanonz.github.io
2 stars 2 forks source link

使用 React Context API 和 Hooks 实现全局状态管理和性能优化 #22

Open sanonz opened 3 years ago

sanonz commented 3 years ago

https://sanonz.github.io/2020/state-management-and-performance-optimization-for-react-context-api-with-hooks/

aslinwang commented 3 years ago

aaa

seateam commented 2 years ago

reducer 函数使用对象深合并,使用起来更加丝滑,希望可以加个好友!

定义:

import merge from 'lodash.merge'

const reducer = (state, data) => {
  return { ...merge(state, data) }
}

更新:

dispatch({
  count: state.count + 1,
  account: {
    displayName: account.username,
    email: account.email,
  },
})