Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
38 lines (25 loc) · 2.01 KB

File metadata and controls

38 lines (25 loc) · 2.01 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

1> We create a store, using the createStore function. We pass it our reducer, and then use the compose function to create a single function from two other functions. It takes other middlewares and returns a single enhancer function from it. We are creating our middleware using the applyMiddleware function and passing it our thunk library.

import { createStore, applyMiddleware, compose } from "redux";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import reducer from "./reducer";

const store = createStore(
  reducer,
  compose(
    applyMiddleware(thunk),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )
);

https://scotch.io/courses/getting-started-with-react-and-redux/setting-up-the-redux-store

2> Official Doc

createStore(reducer, [preloadedState], [enhancer])

Creates a Redux that holds the complete state tree of your app.

There should only be a single store in your app.

Arguments

  1. reducer (Function): A reducing function that returns the next state tree, given the current state tree and an action to handle.

  2. [preloadedState] (any): The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced reducer with combineReducers, this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your reducer can understand.

  3. [enhancer] (Function): The store enhancer. You may optionally specify it to enhance the store with third-party capabilities such as middleware, time travel, persistence, etc. The only store enhancer that ships with Redux is applyMiddleware()

Returns

Store : An object that holds the complete state of your app. The only way to change its state is by dispatching actions. You may also subscribe to the changes to its state to update the UI.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.