I found two ways to configure redux createStore ,
1.https://github.com/TeamWithBR/SampleProjectTodo/blob/master/src/store/configureStore.js
2.https://github.com/aknorw/piHome/blob/9f01bc4807a8dfe2a75926589508285bff8b1ea6/app/configureStore.js
Which is preferable?
createStore(reducer, [preloadedState], [enhancer]) Creates a Redux store that holds the complete state tree of your app. There should only be a single store in your app.
Middleware helps you with logging, error reporting, making asynchronous requests, and a whole lot more. Take a look at the below code: import React from "react"; import ReactDOM from "react-dom"; import { createStore } from "redux"; const reducer = (state = 0, action) => { switch (action.
middleware) Middleware is the suggested way to extend Redux with custom functionality. Middleware lets you wrap the store's dispatch method for fun and profit. The key feature of middleware is that it is composable.
( 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. Don't create more than one store in an application! Instead, use combineReducers to create a single root reducer out of many.
Which is preferable? createStoreWithMiddleware is the old way to create the store with enhancers in Redux. In Redux version 3.1.0, a new approach has been introduced and now createStore receives an enhancer such as applyMiddleware () as the last optional argument.
createStore (reducer, [preloadedState], [enhancer]) Creates a Redux store that holds the complete state tree of your app. There should only be a single store in your app.
useRef: The useRef is a hook that uses the same ref throughout. It saves its value between re-renders in a functional component and doesn’t create a new instance of the ref for every re-render. It persists the existing ref between re-renders. createRef: The createRef is a function that creates a new ref every time.
createStoreWithMiddleware
is the old way to create the store with enhancers in Redux. In Redux version 3.1.0, a new approach has been introduced and now createStore
receives an enhancer such as applyMiddleware()
as the last optional argument.
Now, the new createStore
approach is preferable as it leads to code that is easier to read and reason about, but both will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With