Sunday, May 19, 2024
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 17376  / 6 Years ago, wed, december 12, 2018, 12:00:00

I'm following the Let’s Build: Cryptocurrency Native Mobile App With React Native + Redux tutorial.



When I create my store in App.js, the app works fine



import { createStore, applyMiddleware, compose } from 'redux';
import devTools from 'remote-redux-devtools';
import React, { Component } from 'react';
import { Platform, View } from 'react-native';
import { Provider } from 'react-redux';
import promise from 'redux-promise';
import thunk from 'redux-thunk';
import logger from 'redux-logger';

import { Header, CryptoContainer } from './src/components';
import rootReducer from './src/reducers';

const middleware = applyMiddleware(thunk, promise, logger);

const Store = createStore(rootReducer, compose(middleware, devTools({
name: Platform.OS,
hostname: 'localhost',
port: 5678
}), ));

export default class App extends Component {
render() {
return (
<Provider store={Store}>
<View>
<Header />
<CryptoContainer />
</View>
</Provider>
);
}
}


but when I move the store logic to a new file ./src/Store.js,



import { Platform } from 'react-native';    
import { createStore, applyMiddleware, compose } from 'redux';
import devTools from 'remote-redux-devtools';
import promise from 'redux-promise';
import thunk from 'redux-thunk';
import logger from 'redux-logger';

import rootReducer from './reducers';

const middleware = applyMiddleware(thunk, promise, logger);

const Store = createStore(rootReducer,compose(middleware,devTools({
name: Platform.OS,
hostname: 'localhost',
port: 5678
}),
)
);

export default Store;


and use it in App.js like



import React, { Component } from 'react';
import { View } from 'react-native';
import { Provider } from 'react-redux';

import { Header, CryptoContainer } from './src/components';
import { Store } from './src/Store';

export default class App extends Component {
render() {
return (
<Provider store={Store}>
<View>
<Header />
<CryptoContainer />
</View>
</Provider>
);
}
}


I get




TypeError: undefined is not an object (evaluating 'store.getState')




What's causing my build (expo start) to fail when I import Store.js?


More From » react-native

 Answers
28

It seems the import statement is not right. It should be:



import Store from './src/Store';

[#52935] Thursday, December 6, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mariamiyanab

Total Points: 75
Total Questions: 102
Total Answers: 92

Location: British Indian Ocean Territory
Member since Tue, Feb 22, 2022
2 Years ago
;