I'm trying to connect multiple stores on a component. I tried the example on the docs: https://react-redux.js.org/using-react-redux/accessing-store, but throw errors when create Context:
Error
Context<{ onSession: boolean; }>' is not assignable to type 'Context<ReactReduxContextValue<any, AnyAction>>'.
And if I use only the compose without Context, does not recognize the component:
Error
JSX element type 'Main' does not have any construct or call signatures.
Has someone knows how to connect multiple stores?
This is how the implementation is going:
index.tsx
const initialA = {
onSession: false
};
const ContextA = React.createContext(initialA);
const store = configureStoreSession();
return (
<div className="app">
<div className="app-container">
<Provider store={store} context={ContextA}>
<Covenants />
</Provider>
</div>
</div>
);
}
main.tsx
type MainProps = {
onSession: boolean;
};
function Main({ onSession }: MainProps) {
return (
<div>Has session? {onSession}</div>
)
}
const mapStateA = (state: AppStateA) => {
return {
filters: state.stateA.filters
};
};
const mapStateB = (state: AppStateB) => {
return {
onSession: state.stateB.onSession
};
};
const mapDispatchA = {};
const mapDispatchB = {};
export default compose(
connect(mapStateA, mapDispatchA),
connect(mapStateB, mapDispatchB)
)(Main);