UNPKG

@gechiui/compose

Version:
50 lines (45 loc) 1.5 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@gechiui/element"; /** * GeChiUI dependencies */ import { Component } from '@gechiui/element'; import deprecated from '@gechiui/deprecated'; /** * Internal dependencies */ import createHigherOrderComponent from '../../utils/create-higher-order-component'; /** * A Higher Order Component used to provide and manage internal component state * via props. * * @deprecated Use `useState` instead. * * @param {any} initialState Optional initial state of the component. * * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props. */ export default function withState() { let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; deprecated('gc.compose.withState', { since: '5.8', alternative: 'gc.element.useState' }); return createHigherOrderComponent(OriginalComponent => { return class WrappedComponent extends Component { constructor( /** @type {any} */ props) { super(props); this.setState = this.setState.bind(this); this.state = initialState; } render() { return createElement(OriginalComponent, _extends({}, this.props, this.state, { setState: this.setState })); } }; }, 'withState'); } //# sourceMappingURL=index.js.map