Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access the store in a child component with existing props #34

Open
shansubra opened this issue Jan 22, 2021 · 0 comments
Open

How to access the store in a child component with existing props #34

shansubra opened this issue Jan 22, 2021 · 0 comments

Comments

@shansubra
Copy link

shansubra commented Jan 22, 2021

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant