Skip to content

Could you add something so that you can use the provider and the context in the same component? Maybe add an HOC like withContainer()? #82

Open
@niamleeson

Description

@niamleeson

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

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