UNPKG

@vtex/styleguide

Version:

> VTEX Styleguide React components ([Docs](https://vtex.github.io/styleguide))

46 lines (35 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBodyContext = useBodyContext; exports.BodyProvider = BodyProvider; var _react = require("react"); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var BodyContext = (0, _react.createContext)(null); function useBodyContext() { var context = (0, _react.useContext)(BodyContext); if (!context) { throw new Error('Do not use body components outside of the BodyContext'); } return context; } function BodyProvider(_ref) { var children = _ref.children, onRowClick = _ref.onRowClick, isRowActive = _ref.isRowActive, rowKey = _ref.rowKey, highlightOnHover = _ref.highlightOnHover; var value = _react2.default.useMemo(function () { return { onRowClick: onRowClick, isRowActive: isRowActive, rowKey: rowKey, highlightOnHover: highlightOnHover }; }, [highlightOnHover, isRowActive, onRowClick, rowKey]); return _react2.default.createElement(BodyContext.Provider, { value: value }, children); }