react-store
react-store copied to clipboard
How to access the store in a child component with existing props
How do I access the react context api store in my child component which already takes some props & state? When I try to access this.props.store.get("amount") (based on your example) I am getting an error "cannot access property of undefined.
import { withStore } from "@spyna/react-store";
class Child1 extends React.Component<ICustomProps & IAppProps, IAuthState> {
render() {
return (
<p>My Amount: {this.props.store.get('amount')}</p>
)
}
}
export default withStore(Child1)
App component:
import { createStore } from "@spyna/react-store";
class App extends React.Component<IAppProps> {
render() {
<Route component={this.AppWithAuthenticationConfigured}/>
}
}
const initialValue = {
amount: 15,
username: {
name: "spyna",
url: "https://spyna.it"
}
};
export default createStore(App, initialValue);