anish000kumar / redux-box

Modular and easy-to-grasp redux based state management, with least boilerplate
MIT License
708 stars 22 forks source link

Cannot read property 'sagas' of undefined #21

Closed ramyareye closed 6 years ago

ramyareye commented 6 years ago

Hi,

After using this lines I got the error :

import store from "../store/index" // points to store/index.js file

const accessToken = store.getState().auth.accessToken;

console.log('accessToken', accessToken)

Possible to be a bug or my code mistaken ?

Thanks

anish000kumar commented 6 years ago

Try using dynamic import instead.

const store = () => require("../store/index").default;
const accessToken = store().getState().auth.accessToken;
ramyareye commented 6 years ago

no hope this is my index.js

import React from 'react'
import { Provider } from "react-redux"
import { AppRegistry } from 'react-native'

import App from './app/App'
import store from 'store'

const Application = () => (
  <Provider store={store}>
    <App />
  </Provider>
)

AppRegistry.registerComponent('App', () => Application)

If I import store before the App the error is gone but then .getState() doesn't work. I'm a bit confused, box is working well inside app but here in my api.js which is called in one of store sagas doesn't, strange!

anish000kumar commented 6 years ago

The issue is caused by static resolution of modules, you should try dynamic imports (using require instead of import) as suggested in my previous comment.