We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Here's a use case. I think the API would be really nice.
import { State } from './state.provider'; const Parent = () => { const { handleAction, currState, component: Component } = State.useContainer(); return ( <Component sendAction={handleAction} pollData={pollData} /> ); }; export default State.withContainer(Parent);
Without the above, you need to do this everytime you create a new state:
import { State } from './state.provider'; const withContainer = (Component) => (props) => ( <State.Provider> <Component {...props} /> </State.Provider> ); const Parent = () => { const { handleAction, currState, component: Component } = State.useContainer(); return ( <Component sendAction={handleAction} pollData={pollData} /> ); }; export default withContainer(Parent);
The text was updated successfully, but these errors were encountered:
@jamiebuilds I just created a PR to fulfill the above ask. Please let me know if the PR doesn't meet your expectations. #83
Sorry, something went wrong.
Work around might be the following, maybe:
import * as React from 'react'; import { createContainer } from 'unstated-next'; const useTeamState = () => { return {}; }; export const TeamStateContainer = createContainer(useTeamState); export type TeamContainerState = ReturnType<typeof useTeamState>; function withTeamContainer<P extends object>(Component: React.ComponentType<P>) { const WrappedComponent = (props) => { return ( <TeamStateContainer.Provider> <Component {...props} /> </TeamStateContainer.Provider> ); }; return WrappedComponent; } export default withTeamContainer;
I use this function:
// connect.js const connect = (Component, ...providers) => () => providers.reduce( (children, Provider) => <Provider>{children}</Provider>, <Component /> )
Then in the containers:
// myContainerComponent.jsx export default connect(Welcome, SomeProvider, AnotherProvider)
No branches or pull requests
Here's a use case. I think the API would be really nice.
Without the above, you need to do this everytime you create a new state:
The text was updated successfully, but these errors were encountered: