javascript - React Native TypeError store.getState is not a function - Stack Overflow

admin2025-04-17  0

Hi guys I'm trying to make my code more readable and pragmmatic.

Using redux-saga in React Native I'm getting some issues.

When I try to load the app I get the error:

TypeError: store.getState is not a function

This error is located at:

in Connect(Reprov) (at App.js:17)
in RCTView (at View.js:44)
in Provider (at App.js:14)
in App (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)

src/store/configureStore.js


import {createStore, applyMiddleware} from 'redux'
import createSagaMiddleware from 'redux-saga';
import rootReducer from '../reducers';
import rootSaga from '../sagas';

export default function () {
  const sagaMiddleware = createSagaMiddleware();
  const store = createStore(
    rootReducer,
    applyMiddleware(sagaMiddleware)
  );

  sagaMiddleware.run(rootSaga)

  return store;
}

src/App.js

import React, {Component} from 'react'
import { View } from 'react-native';
import { Provider } from 'react-redux';
import AppNavigation from './Navigation';
import store from './store/configureStore';
import Reproof from './screens/Reprov';
import Approval from './screens/Aprov';
import PushNotificationController from './ponents/Push';

class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <View style={{ flex: 1 }}>
          <AppNavigation />
          <Reproof />
          <Approval />
          <PushNotificationController />
        </View>
      </Provider>
    )
  }
}

export default App;

I don't know what I'm doing wrong...

Hi guys I'm trying to make my code more readable and pragmmatic.

Using redux-saga in React Native I'm getting some issues.

When I try to load the app I get the error:

TypeError: store.getState is not a function

This error is located at:

in Connect(Reprov) (at App.js:17)
in RCTView (at View.js:44)
in Provider (at App.js:14)
in App (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)

src/store/configureStore.js


import {createStore, applyMiddleware} from 'redux'
import createSagaMiddleware from 'redux-saga';
import rootReducer from '../reducers';
import rootSaga from '../sagas';

export default function () {
  const sagaMiddleware = createSagaMiddleware();
  const store = createStore(
    rootReducer,
    applyMiddleware(sagaMiddleware)
  );

  sagaMiddleware.run(rootSaga)

  return store;
}

src/App.js

import React, {Component} from 'react'
import { View } from 'react-native';
import { Provider } from 'react-redux';
import AppNavigation from './Navigation';
import store from './store/configureStore';
import Reproof from './screens/Reprov';
import Approval from './screens/Aprov';
import PushNotificationController from './ponents/Push';

class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <View style={{ flex: 1 }}>
          <AppNavigation />
          <Reproof />
          <Approval />
          <PushNotificationController />
        </View>
      </Provider>
    )
  }
}

export default App;

I don't know what I'm doing wrong...

Share asked Oct 14, 2018 at 13:18 Wes GuirraWes Guirra 1933 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You are importing the store as a variable and in the file,it is a function :

import store from './store/configureStore';

try this :

import configureStore from './store/configureStore';

then create a variable store

const store = configureStore();
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744884815a272473.html

最新回复(0)