According to my understanding, whatever is displayed in the save:
function is what is shown on the page in the front end?
So I am trying to query the database from my block to get information I am storing there but I cannot figure out how to use the fetch()
function in the save:
area.
when I change the code in save:
to this the block says it contains unexpected or invalid content, but the block still works.
save: function(props) {
return wp.element.createElement(
"div",
{ style: { border: "3px solid " + props.attributes.color } },
'foobar baz'
);
}
})
do I have to use props here or something?
edit
andsave
functions don't need to be similar at all. You could have totally different HTML in each. Does this help with what you are trying to achieve?save
function's output whatever you need it to be - it doesn't have to matchedit
at all. Theedit
andsave
functions' only requirements are that they return something, and that you provide a way for them to interact with the attributes. While you're editing, it's best practice to usewp.element.createElement
rather thanReact.createElement
.