Skip to content

Use React context with provider/consumer to pass status #23

@ramyma

Description

@ramyma

I am using the Online and Offline components in a couple of places within my application and noticed that the application is hitting the polling url every 5 seconds about 3 times, which shows that each Online/Offline component checks separately for the connection's status.

I propose creating a Provider which could be used to wrap the application's root component and just use a Consumer anywhere where the connection status is needed.

It would look something like:

<Provider {...config}>
  <App />
</Provider>
<Consumer>
  {({ online }) => (
    <div>
      {`${online}`}
    </div>
  )}
</Consumer>

I can create a PR to implement it if it's OK.

What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    v3possible v3.0.0 features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions