The Redux “store” carries together all the states, reducers, and actions that create the app. The store has multiple responsibilities:

  • It holds the state of the current application from inside
  • With the help of store.getState(); it allows access to the current state.
  • With the help of the store.dispatch(action); it allows the state to be updated.
  • With the help of the store.subscriber(listener); it allows to register listener callbacks.

Store Methods

  • getState()
  • dispatch(action)
  • subscribe(listener)
  • replaceReducer(nextReducer)
BY Best Interview Question ON 31 May 2021

Example

import { createStore } from 'redux'
const store = createStore(todos, ['Use Redux'])

function addTodo(text) {
  return {
    type: 'ADD_TODO',
    text
  }
}

store.dispatch(addTodo('Read the docs'))
store.dispatch(addTodo('Read about the middleware'))