Skip to content

Instantly share code, notes, and snippets.

@jossmac
Last active November 1, 2018 03:21
Show Gist options
  • Save jossmac/4b9dc6e2cd50cb718e9a9d96bc016f7f to your computer and use it in GitHub Desktop.
Save jossmac/4b9dc6e2cd50cb718e9a9d96bc016f7f to your computer and use it in GitHub Desktop.
Pseudo code for a consumer component
import React from 'react';
import { ToastContext } from './Provider';
export const ToastConsumer = ({ children }) => (
<ToastContext.Consumer>
{context => children(context)}
</ToastContext.Consumer>
);
// Higher-Order Component
export const withToastManager = (Comp) => (props) => (
<ToastConsumer>
{context => <Comp toastManager={context} {...props} />}
</ToastConsumer>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment