How to trigger rerender of (gutenberg) block based on boolean variable value?
-
When registering a custom block type. How can one trigger a re-render or update of the block in the editor page.
Example.
Let’s say I have registered a block whose
edit()
function return’s a value of<> <BlockControls><IconButton icon="edit" onclick="toggleBoolean/></BlockControls> {myBoolean ? <Some_JSX_a>...</Some_JSX_a> : <Some_JSX_b>...</Some_JSX_b>}; </>
Now, this doesn’t work, and I am struggling with some key concepts.
First, where do I store
myBoolean
… if this were a regular react app I might keep this in the state of a stateful component.2nd. How do I tell the editor to re-render the block when my button’s click callback fires so that it has the chance to re-evaluate my ternary operator and make the choice between which JSX snippet to render?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to trigger rerender of (gutenberg) block based on boolean variable value?’ is closed to new replies.