Skip to content

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

@shansubra

Description

@shansubra

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions