{"size": 505, "ext": "js", "max_stars_repo_path": "src/withToast.js", "max_stars_repo_name": "trendmicro-frontend/react-toasts", "max_stars_repo_stars_event_min_datetime": "2019-12-15T10:06:57.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-15T10:06:57.000Z", "max_issues_repo_path": "src/withToast.js", "max_issues_repo_name": "trendmicro-frontend/react-toasts", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/withToast.js", "max_forks_repo_name": "trendmicro-frontend/react-toasts", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.5789473684, "max_line_length": 112, "alphanum_fraction": 0.5485148515}
import React from 'react';
import ToastConsumer from './ToastConsumer';

const withToast = (Component) => React.forwardRef((props, ref) => (
    <ToastConsumer>
        {context => {
            if (!context) {
                throw new Error('The `withToast` HOC must be called from a descendent of the `ToastProvider`.');
            }

            return (
                <Component toast={context} {...props} ref={ref} />
            );
        }}
    </ToastConsumer>
));

export default withToast;
