ioof-holdings/redux-subspace

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

Closed this issue · 4 comments

Is it a bug, feature request or question?

It seems a bug, I always get error below when I try the sample code provided in the documentation.

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

Which package(s) does this involve?

react-redux-subspace

Input Code

I created a blank react-native app using Expo, then the App.js files has the following content:

import React from 'react';
import { createStore, combineReducers } from 'redux';
import { namespaced } from 'redux-subspace';
import { Provider } from 'react-redux';
import { SubspaceProvider } from 'react-redux-subspace'
import { StyleSheet, Text, View } from 'react-native';

// dummy reducer
const foo = (state = 42) => state

const rootReducer = combineReducers({
  foo: namespaced('foo')(foo),
})

const store = createStore(rootReducer)

const Foo = () => (
  <View style={styles.container}>
    <Text>Open up App.js to start working on your app!</Text>
  </View>
)

export default () => (
  <Provider store={store}>
    <SubspaceProvider mapState={state => state.foo} namespace="foo">
      <Foo />
    </SubspaceProvider>
  </Provider>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Expected Behavior

I should see a screen with the text Open up App.js to start working on your app!

Current Behavior

I get the following error and stacktrace:

[18:16:27] Warning: Failed context type: The context `store` is marked as required in `SubspaceProvider`, but its value is `undefined`.
- node_modules/prop-types/checkPropTypes.js:20:20 in printWarning
- ... 22 more stack frames from framework internals

[18:16:31] TypeError: undefined is not an object (evaluating 'store.subspaceOptions')

This error is located at:
    in SubspaceProvider (at App.js:28)
    in Provider (at App.js:27)
    in _default (at withExpoRoot.js:22)
    in RootErrorBoundary (at withExpoRoot.js:21)
    in ExpoRootComponent (at renderApplication.js:34)
    in RCTView (at View.js:44)
    in RCTView (at View.js:44)
    in AppContainer (at renderApplication.js:33)
- node_modules/redux-subspace/lib/index.js:377:69 in <unknown>
- node_modules/react-redux-subspace/lib/index.js:37:47 in getChildContext
- ... 21 more stack frames from framework internals

If I remove the SubspaceProvider then the app renders, but of course I don't get the subspace.

Your Setup

Here are my dependencies from package.json:

 "dependencies": {
    "expo": "^32.0.0",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-redux": "^6.0.0",
    "react-redux-subspace": "^3.0.1",
    "redux": "^4.0.1",
    "redux-subspace": "^3.0.1"
  },

Hi @dapicester,

We don't yet support react-redux@^6 yet which changes from legacy React context to the new Context API.

Downgrading to react-redux@^5 should make the issue go away. I know that isn't the ideal answer, and we definitely plan to support version 6 at some point (soon), so I hope this isn't a dealbreaker for you.

If you want to get us there faster, I'll happily accept a PR adding v6 support.

OK, downgrading fixed the issue, and that's good enough for me.
I wonder if that could be documented somehow.

You should have received a peer dependency warning when installing.

We could include versions of in installation instructions but I worry they will get out of sync pretty quickly.

I think the actual thing to do here is to support v6.

v6 support is not longer relevant as we not support v7. Closing this now.