D
D
DemonIa2019-04-10 12:27:15
WordPress
DemonIa, 2019-04-10 12:27:15

How (where) to save the state value of the component after page reload (Gutenberg, React)?

Hello.
I am writing a block for Gutenberg (an editor for WordPress), the essence of which is as follows:
The interface is just a drop-down list with a value loaded by ajax (in componentDidMount)
After saving the post, it is rendered into a block like

<span>Hello, {this.props.attributes.selectedOptionValue} </span>

That is, after choosing an option from the list, I store its value in state, then pass it to the child component and do render there.
Now, I need to make sure that after reloading the page, the previously selected value is <select>not lost. And this means that I need to store the value for the current block somewhere.
It could be stored in WP post_meta, but there can be several of these blocks in one post. So you need to store, for example, post id, block id and dropdown value. And then, when entering the editor, make a request to the server, get the value, and set it as <select value="here">
What are the good practices in this regard?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question