When to use native React.useReducer Hook and how it differentiate from Redux

前端 未结 4 549
一生所求
一生所求 2020-12-23 19:58

So, Hooks are available from React 16.8. From their documentation, Hooks come as a replacer of state in functional components. The basic hooks are: useState,

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 20:09

    So, if Redux and useReducer were to be compared

    Redux:

    • centralised state
    • forges more de-coupling
    • has middlewares: Redux thunk and Redux logger
    • actions can only hit one Store
    • maybe more suitable for big projects

    useReducer:

    • local state
    • no wrapper component
    • needs useContext in order to reinvent the wheel
    • comes with other native hooks
    • no extra dependencies needed
    • multiple stores maybe(actually reducers that can act as store)
    • maybe more suitable for small projects

提交回复
热议问题