import { createElement, Component, createRef } from '@wordpress/element' import OptionsPanel from './OptionsPanel.js' import $ from 'jquery' const INITIAL_VALUE = '__INITIAL__' export default class OptionsRoot extends Component { state = { value: INITIAL_VALUE } input = createRef() static getDerivedStateFromProps(props, state) { if (state.value === INITIAL_VALUE) { return { value: props.value } } return null } render() { return (
{}} name={this.props.input_name} id={this.props.input_id} type="hidden" ref={this.input} /> { this.setState(({ value }) => ({ value: { ...value, ...newValue } })) $(this.input.current).change() }} value={this.state.value} options={this.props.options} />
) } }