Description
I'm having issues using redux connect
on react-pixi-fiber components if the redux provider is not a child of the Stage
component.
The following setup works for me:
// index.js
import Test from 'Test'
const appContainer = document.getElementById('app-container');
render(
<div>
<Test />
<div>...</div>
</div>,
appContainer
);
// Test.js
import TestContainer from 'TestContainer';
const Test = props => {
return(
<Stage>
<Provider store={store}>
<TestContainer />
</Provider>
</Stage>
);
}
export default Test;
// TestContainer.js
const mapStateToProps = state => ({ ...state });
const TestContainer = props => <Container />;
export default connect(mapStateToProps, null)(TestContainer);
However, if I move the Provider
so that it wraps Stage
// Test.js
import TestContainer from 'TestContainer';
const Test = props => {
return(
<Provider store={store}>
<Stage>
<TestContainer />
</Stage>
</Provider>
);
}
export default Test;
I get this error:
Uncaught Error: Could not find "store" in the context of "Connect(TestContainer)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(TestContainer) in connect options.
Ideally I'd like
// index.js
import Test from 'Test'
const appContainer = document.getElementById('app-container');
render(
<Provider store={store}>
<div>
<Test />
<div>...</div>
</div>
<Provider>,
appContainer
);
// Test.js
import TestContainer from 'TestContainer';
const Test = props => {
return(
<Stage>
<TestContainer />
</Stage>
);
}
export default connect(mapStateToProps)(Test);
But it gives me the same error as above.
I can work around this by not using connect
on TestContainer
and instead just passing props down to it (When the redux Provider
is used in index.js
, the connected Test
component does have access to the props from the store), but it would be simpler to use it with connect.
I came across this issue in a similar project (that references pixi-react-fiber, so may be at least partially based on it). Comments there indicate that it's a problem with context in general and not specifically redux. The empty objects here and here look like it might be something similar.
I did a little debugging, but couldn't figure anything out. If this is a solvable issue, I'd love to help out if any contributors could give me some pointers.