Because of the complexity of a project that I inherited, I am trying to access a redux store by importing it, as proposed in https://stackoverflow.com/a/41172768/5532513.
The relevant code in the ts module that is trying to import the store (it is exported from a js module) is provided below.
I am getting the following error while running the code:
ERROR Invariant Violation: Could not find "store" in either the context
or props of "Connect(ServiceUtil)". Either wrap the root component in a
<Provider>, or explicitly pass "store" as a prop to "Connect(ServiceUtil)".
Any idea why?
The relevant code:
import * as React from "react";
import { connect } from 'react-redux';
import { reduxStore as store } from '../main/main';
...
export interface Props_Imp {
a: string;
b : boolean;
};
export interface State_Imp {
};
class Lesson extends React.Component<Props_Imp, State_Imp> {
...
}
const mapStateToProps = (state) => {
return {
a: state.get('a'),
}
}
const mapDispatchToProps = dispatch => {
return {
func1: (number) =>
dispatch({ type: 'FUNC1', payload: number}),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Lesson);