Sobes.tech
Middle+

How have you worked with state managers? Have you used Redux?

sobes.tech AI

Answer from AI

I have worked with various state managers, including Redux, MobX, and Context API in React. I used Redux for managing global state in large applications where predictable behavior and debugging capabilities through tools like Redux DevTools are important.

Example of using Redux:

import { createStore } from 'redux';

// Reducer
function counter(state = 0, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
}

const store = createStore(counter);

store.dispatch({ type: 'INCREMENT' });
console.log(store.getState()); // 1

Redux helps to centralize state, especially when data is needed in different parts of the application.