0

How can I use hooks instead of redux in react?

28th Jul 2020, 12:39 PM
Sepideh
Sepideh - avatar
4 Respuestas
+ 1
Context API is a good option when we do not have frequency updates..but I need to use it somewhere which will update most of the time.
28th Jul 2020, 2:30 PM
Sepideh
Sepideh - avatar
+ 1
Use MobX it has hooks implementation
28th Jul 2020, 2:37 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
You can use context API
28th Jul 2020, 1:26 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
useReducer is a hook in React that allows you to manage state in a function component using a reducer function. A reducer function is a function that takes the current state and an action, and returns the new state. Here's an example of using useReducer to manage a simple counter state in a React component: import React, { useReducer } from 'react'; const initialState = { count: 0 }; function reducer(state, action) { switch (action.type) { case 'increment': return { count: state.count + 1 }; case 'decrement': return { count: state.count - 1 }; default: throw new Error(); } } function Counter() { const [state, dispatch] = useReducer(reducer, initialState); return ( <div> <p>Count: {state.count}</p> <button onClick={() => dispatch({ type: 'increment' })}>+</button> <button onClick={() => dispatch({ type: 'decrement' })}>-</button> </div> ); }
25th Dec 2022, 5:16 AM
Calviղ
Calviղ - avatar