+1 vote
in Redux by
What is Store? How to create Store in React?

1 Answer

0 votes
by
A Store is an Object which holds the whole state tree of your application.

import React, { Component } from "react";

import { createStore } from "redux";

const initialState = {

  lang_code: "en",

};

const langReducer = (state = initialState, action) => {

  //make a copy of initialState

  //(you can also use - Object.assign({}, state))

  let newState = {...state};

  if (action.type === "SET_LANGUAGE") {

    newState.lang_code = action.lang_code;

  }

  return newState;

};

const store = createStore(langReducer);

Related questions

0 votes
asked Dec 14, 2023 in ReactJS by rahuljain1
0 votes
asked Aug 28, 2022 in Redux by john ganales
...