@wordpress/compose
Version:
WordPress higher-order components (HOCs).
35 lines (34 loc) • 993 B
JavaScript
// packages/compose/src/higher-order/with-state/index.js
import { Component } from "@wordpress/element";
import deprecated from "@wordpress/deprecated";
import { createHigherOrderComponent } from "../../utils/create-higher-order-component";
import { jsx } from "react/jsx-runtime";
function withState(initialState = {}) {
deprecated("wp.compose.withState", {
since: "5.8",
alternative: "wp.element.useState"
});
return createHigherOrderComponent((OriginalComponent) => {
return class WrappedComponent extends Component {
constructor(props) {
super(props);
this.setState = this.setState.bind(this);
this.state = initialState;
}
render() {
return /* @__PURE__ */ jsx(
OriginalComponent,
{
...this.props,
...this.state,
setState: this.setState
}
);
}
};
}, "withState");
}
export {
withState as default
};
//# sourceMappingURL=index.js.map