UNPKG

@featbit/react-client-sdk

Version:
36 lines 1.63 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import * as React from 'react'; import { Consumer } from './context'; /** * withFbConsumer is a function which accepts an optional options object and returns a function * which accepts your React component. This function returns a HOC with flags * and the FB instance injected via props. * * @param options - If you need only the `fbClient` instance and not flags, then set `{ clientOnly: true }` * to only pass the fbClient prop to your component. Defaults to `{ clientOnly: false }`. * @return A HOC with flags and the `fbClient` instance injected via props */ function withFbConsumer(options) { if (options === void 0) { options = { clientOnly: false }; } return function withFbConsumerHoc(WrappedComponent) { return function (props) { return (React.createElement(Consumer, null, function (_a) { var flags = _a.flags, fbClient = _a.fbClient; if (options.clientOnly) { return React.createElement(WrappedComponent, __assign({ fbClient: fbClient }, props)); } return React.createElement(WrappedComponent, __assign({ flags: flags, fbClient: fbClient }, props)); })); }; }; } export default withFbConsumer; //# sourceMappingURL=withFbConsumer.js.map