UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

44 lines 1.97 kB
import { __assign, __extends } from "tslib"; import { invariant } from "../../utilities/globals/index.js"; import * as React from "react"; import hoistNonReactStatics from "hoist-non-react-statics"; import { ApolloConsumer } from "../context/index.js"; function getDisplayName(WrappedComponent) { return WrappedComponent.displayName || WrappedComponent.name || "Component"; } export function withApollo(WrappedComponent, operationOptions) { if (operationOptions === void 0) { operationOptions = {}; } var withDisplayName = "withApollo(".concat(getDisplayName(WrappedComponent), ")"); var WithApollo = (function (_super) { __extends(WithApollo, _super); function WithApollo(props) { var _this = _super.call(this, props) || this; _this.setWrappedInstance = _this.setWrappedInstance.bind(_this); return _this; } WithApollo.prototype.getWrappedInstance = function () { invariant(operationOptions.withRef, 46); return this.wrappedInstance; }; WithApollo.prototype.setWrappedInstance = function (ref) { this.wrappedInstance = ref; }; WithApollo.prototype.render = function () { var _this = this; return (React.createElement(ApolloConsumer, null, function (client) { var props = Object.assign({}, _this.props, { client: client, ref: operationOptions.withRef ? _this.setWrappedInstance : undefined, }); return React.createElement(WrappedComponent, __assign({}, props)); })); }; WithApollo.displayName = withDisplayName; WithApollo.WrappedComponent = WrappedComponent; return WithApollo; }(React.Component)); return hoistNonReactStatics(WithApollo, WrappedComponent, {}); } //# sourceMappingURL=withApollo.js.map