@wordpress/compose
Version:
WordPress higher-order components (HOCs).
8 lines (7 loc) • 2 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/higher-order/with-state/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @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.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"],
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AAKvB,SAAS,kCAAkC;AA8BtC;AAlBU,SAAR,UAA4B,eAAe,CAAC,GAAI;AACtD,aAAY,wBAAwB;AAAA,IACnC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,SAAO,2BAA4B,CAAE,sBAAuB;AAC3D,WAAO,MAAM,yBAAyB,UAAU;AAAA,MAC/C,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,WAAW,KAAK,SAAS,KAAM,IAAK;AAEzC,aAAK,QAAQ;AAAA,MACd;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK;AAAA,YACR,GAAG,KAAK;AAAA,YACV,UAAW,KAAK;AAAA;AAAA,QACjB;AAAA,MAEF;AAAA,IACD;AAAA,EACD,GAAG,WAAY;AAChB;",
"names": []
}