'React-Redux | Invalid Hook Call

As I am new to redux i got into the following error.

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

store.js file

import { combineReducers, applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import { composeWithDevTools } from '@redux-devtools/extension';
 
const reducer = combineReducers({
    //combine all the reducers
});

const initialState = {};
const middleware = [thunk];

const store = createStore(
        reducer, 
        initialState,
        composeWithDevTools(applyMiddleware(...middleware))
);

export default store;

index.js file

import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import reportWebVitals from './reportWebVitals';
import { Provider } from 'react-redux';
import store from './redux/store'


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


reportWebVitals();

when i add app tag inside provider tag it gives error otherwise it works fine as it doesnot use redux in that case.

package.json (server side)

package.json (client side)

Any help will be appreciated. Thankyou



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source