Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between createStore and createStoreWithMiddleware in react?

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?

like image 798
Deepak Kumar Padhy Avatar asked May 27 '17 07:05

Deepak Kumar Padhy


People also ask

What is createStore in React?

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.

What are Middlewares in React?

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.

What is applyMiddleware in react redux?

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.

What is the use of store in react?

( 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 better createstorewithmiddleware or applymiddleware in Redux?

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.

What is createstore in Redux?

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.

What is the difference between useref and createref in react?

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.


1 Answers

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.

like image 155
Tharaka Wijebandara Avatar answered Oct 29 '22 20:10

Tharaka Wijebandara