I am getting this error: TypeError: store.getState is not a function

mai mohamed

I am getting the error :'TypeError: store.getState is not a function' and I can't determine where the problem is

here's how I created the store:

import { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';

import rootReducer from './rootReducer';

const initialState = {
  pending: false,
  products: [],
  error: null
}
const middlewares = [thunk];

export const store=createStore(rootReducer, initialState, applyMiddleware(...middlewares));

and here's the index.js:

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

import App from "./App";
  ReactDOM.render(
  <Provider store={store}>
  
      
        <App />
        
  </Provider>,
  document.getElementById("root")
);

and here's the thunk function:

function fetchProducts() {
    return dispatch => {
        dispatch(fetchProductsPending());
        fetch('https://api.spacexdata.com/v3/launches')
        .then(res => res.json()
        
        )
        .then(
          res => {
            if(res.error) {
                throw(res.error);
            }
            dispatch(fetchProductsSuccess(res.products));
            return res.products;
        })
        .catch(error => {
            dispatch(fetchProductsError(error));
        })
    }
}

export default fetchProducts;

and here's a sandbox of the problem:

https://codesandbox.io/s/polished-sunset-wxefc?file=/src/index.js

here's a screenshot of the error:

enter image description here

Trevor Manz

The store is not the default export from the ./App.jsx module. You either need to add curly braces to your import or export store as the default:

// App.jsx

export const store = /* ... */

// index.js
import { store } from './App';

or

// App.jsx

export default const store = /* ... */

// index.js
import store from './App';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem?

I am getting this error: 'TypeError: callback is not a function', but the function is still executing

I am getting this error message: TypeError: 'function' object is not iterable

Why am I getting ERROR TypeError: "xyz" is not a function?

I am getting Error saying "TypeError: callback is not a function"

Why am I getting this error: TypeError: SpreadsheetApp.getSpreadsheetById is not a function

TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined

I am getting error as $ is not a function

Uncaught TypeError: store.getState is not a function

React Native TypeError store.getState is not a function

TypeError: store.getState is not a function (redux)

I am getting TypeError saying forEach is not a function?

Why am I getting TypeError X is not a function

I am getting TypeError is not a function in nodeJS

Why am I getting 'Uncaught TypeError' error?

Why am I getting a TypeError: Object(...) is not a function error when using redux?

I'm trying to send emails using sendgrid in nodejs.But am getting "TypeError: object is not a function" error

TypeError: file1(...).copyColumns.copyTo is not a function. I am getting this error on apps script

Why am I getting this error?pipe is not a function

Why am I getting a "Function is unused" error?

why I am getting this error "undefined is not a function "

Why am I getting a '.then is not function error'?

Why am I getting the error "is not a function" here?

Why am I getting "Subscribe is not a function" error?

Why am I getting a "no matching function" error?

Why am i getting error in function addRandomNumbers?

By using useNavigate() function, I am getting this error

TypeError: store.getState is not a function in react-redux

react-redux : TypeError: store.getState is not a function