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

withContainer HOC #15

Closed
diegohaz opened this issue May 19, 2018 · 0 comments
Closed

withContainer HOC #15

diegohaz opened this issue May 19, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@diegohaz
Copy link
Owner

diegohaz commented May 19, 2018

const CounterContainer = props => (
  <Container
    initialState={{ count: 0 }}
    actions={{ increment: () => state => ({ count: state.count + 1 }) }}
    {...props}
  />
);

const withContainer = (Container, containerProps) => WrappedComponent => props => (
  <Container {...containerProps}>
    {state => <WrappedComponent {...props} {...state} />}
  </Container>
);

const Counter = ({ count, increment }) => (
  <button onClick={increment}>{count}</button>
);

export default withContainer(CounterContainer)(Counter);
@diegohaz diegohaz added the enhancement New feature or request label May 19, 2018
@diegohaz diegohaz changed the title withContainer withContainer HOC May 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant