project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

createStore got deprecated

Open solodev02 opened this issue 2 years ago • 8 comments

Screenshot 2022-06-19 135601 getting a error after installing react-toolkit because createStore function is no more present in the 'redux' module what to do? it was told in the video that once we paste the json file we don't have to install anymore dependencies any more for client , may we this could be the reason for the error? how to fix it.

solodev02 avatar Jun 19 '22 08:06 solodev02

Apparently, when you install the redux toolkit createStore() becomes depreciated, you can replace it with configureStore() which wraps createStore() to provide simplified configuration options.

A good example to config a store is:

import React from 'react'; import ReactDOM from 'react-dom/client'; import { Provider } from 'react-redux'; import { configureStore } from "@reduxjs/toolkit";

import reducers from "./reducers";

import App from './App';

const store = configureStore({ reducer: reducers })

you can check out the redux toolkit solution to configureStore https://redux.js.org/usage/configuring-your-store#the-solution-configures

Hopefully this helps.

NgatiaJeffers avatar Jun 22 '22 11:06 NgatiaJeffers

Getting the same issue... please advise with an example from the video ex(reducer, middleware, etc)

EduardoBDonovan avatar Jul 12 '22 18:07 EduardoBDonovan

Getting the same issue... please advise with an example from the video ex(reducer, middleware, etc)

I think this should work:

import { Provider } from 'react-redux'; // initialize redux' import { applyMiddleware, compose } from 'redux'; import { configureStore } from '@reduxjs/toolkit'; import thunk from 'redux-thunk'; import reducers from './reducers';

import App from './App';

const store = configureStore(reducers, compose(applyMiddleware(thunk)));

nathanlao avatar Sep 10 '22 05:09 nathanlao

I'm stuck on this step as well. The error im getting is this.

image

My code looks like this.

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { applyMiddleware, compose} from 'redux';
import { configureStore } from '@reduxjs/toolkit';
import thunk from 'redux-thunk';

import reducers from './reducers';
import App from './App'

//const store = createStore(reducers,compose(applyMiddleware(thunk)))
const store = configureStore({reducer: reducers}, compose(applyMiddleware(thunk)));
//const store = configureStore({reducer: reducers});

ReactDOM.render(
<Provider STORE={store}>
    <App />
</Provider>, document.getElementById('root'));

Gagenrllc avatar Sep 27 '22 19:09 Gagenrllc

I'm stuck on this step as well. The error im getting is this.

image

My code looks like this.

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { applyMiddleware, compose} from 'redux';
import { configureStore } from '@reduxjs/toolkit';
import thunk from 'redux-thunk';

import reducers from './reducers';
import App from './App'

//const store = createStore(reducers,compose(applyMiddleware(thunk)))
const store = configureStore({reducer: reducers}, compose(applyMiddleware(thunk)));
//const store = configureStore({reducer: reducers});

ReactDOM.render(
<Provider STORE={store}>
    <App />
</Provider>, document.getElementById('root'));

Apparently what I'm thinking is you are using the latest redux toolkit, Assuming that I would urge you to consider this solution

All the logic related to configuring the store - including importing reducers, middleware, and enhancers - is handled in a dedicated file in a configureStore function

import React from 'react'; import ReactDOM from 'react-dom/client'; import { Provider } from 'react-redux'; import { configureStore } from "@reduxjs/toolkit";

import reducers from "./reducers";

import App from './App';

const store = configureStore({ reducer: reducers })

You could refer to the redux toolkit for more clarity. https://redux.js.org/usage/configuring-your-store#the-solution-configurestore

NgatiaJeffers avatar Sep 28 '22 07:09 NgatiaJeffers

For the record this has nothing to do with your actual application code. It is specifically a message to users like you who are using "plain Redux" - it's trying to tell you that you're following patterns that are much harder to use, and we want you to use Redux Toolkit instead because it will make your life much easier :)

You'll note that this isn't even a runtime warning being printed in the console - it's literally just a visual indicator in your editor, like createStore.

ghost avatar Nov 27 '22 11:11 ghost

I'm stuck on this step as well. The error im getting is this. image My code looks like this.

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { applyMiddleware, compose} from 'redux';
import { configureStore } from '@reduxjs/toolkit';
import thunk from 'redux-thunk';

import reducers from './reducers';
import App from './App'

//const store = createStore(reducers,compose(applyMiddleware(thunk)))
const store = configureStore({reducer: reducers}, compose(applyMiddleware(thunk)));
//const store = configureStore({reducer: reducers});

ReactDOM.render(
<Provider STORE={store}>
    <App />
</Provider>, document.getElementById('root'));

Apparently what I'm thinking is you are using the latest redux toolkit, Assuming that I would urge you to consider this solution

All the logic related to configuring the store - including importing reducers, middleware, and enhancers - is handled in a dedicated file in a configureStore function

import React from 'react'; import ReactDOM from 'react-dom/client'; import { Provider } from 'react-redux'; import { configureStore } from "@reduxjs/toolkit";

import reducers from "./reducers";

import App from './App';

const store = configureStore({ reducer: reducers })

You could refer to the redux toolkit for more clarity. https://redux.js.org/usage/configuring-your-store#the-solution-configurestore

Hey, tried your fix but it didnt work.

Check out my code par the same issue.

Will appreciate your assistance.

https://github.com/adrianhajdin/project_mern_memories/issues/177#issue-2028978845

AAdewunmi avatar Dec 07 '23 16:12 AAdewunmi

FYI: @solodev02, @EduardoBDonovan, @Gagenrllc

Issue fixed! If you are having issues with Redux createStore() being depreciated, here's how to use configureStore():

  1. Run on server side console ->

NPM

npm install @reduxjs/toolkit

Yarn

yarn add @reduxjs/toolkit

  1. Include configureStore() in your client/src/index.js file
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
// import { createStore, applyMiddleware, compose} from "redux";
// import thunk from "redux-thunk";
import { configureStore } from "@reduxjs/toolkit";
import reducers from "./reducers";
import App from "./App";
import "./index.css";

// const store = createStore(reducers, compose(applyMiddleware(thunk)));
const store = configureStore({ reducer: reducers });
ReactDOM.render(
    <Provider store={store}>
       <App />
    </Provider>,
  document.getElementById("root")
);

Job done!

Screenshot 2023-12-25 at 10 11 16

Screenshot 2023-12-25 at 10 11 43

AAdewunmi avatar Dec 25 '23 10:12 AAdewunmi