UNPKG

react-breakpoints

Version:

A library that allows you to mount/unmount components depending on the viewport size. Welcome to the next level of responsive React applications.

32 lines (29 loc) 1.23 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; import React from 'react'; import PropTypes from 'prop-types'; import hoistStatics from 'hoist-non-react-statics'; import BreakpointsContext from './BreakpointsContext'; import { Consumer } from './BreakpointsContext'; var withBreakpoints = function withBreakpoints(Component) { // Remove conditional application of forwardRef in 4.0 var C = React.forwardRef ? React.forwardRef(function (props, ref) { return React.createElement( Consumer, null, function (context) { return React.createElement(Component, _extends({}, props, { ref: ref }, context)); } ); }) : function (props) { return React.createElement( Consumer, null, function (context) { return React.createElement(Component, _extends({}, props, context)); } ); }; C.displayName = 'withBreakpoints(' + (Component.displayName || Component.name) + ')'; return hoistStatics(C, Component); }; export default withBreakpoints;