Prevent FormTokenField component to accept random entries

On a recent project I handled this by just filtering out invalid values in the onChange callback: export default () => { const [value, setValue] = useState([]); const suggestions = [‘lorem’, ‘ipsum’, ‘dolor’, ‘sit’, ‘amet’]; const onChange = (tokens) => { const value = tokens.filter((t) => suggestions.includes(t)); setValue(value); }; return <FormTokenField onChange={onChange} suggestions={suggestions} value={value} />; … Read more

Filtering Gutenberg Components, not Blocks

No, you cannot. You can add extra controls to a blocks toolbar or inspector because filters were added to the code that constructs those user interfaces. Think of it as being handed lego buildings before they’re placed as an opportunity to add extra bricks. What you’ve asked however is filtering individual components, which is not … Read more

Can this react script be optimized? How to make it faster

Of course it never changes, because you told it that it never changes: // Selected page list const { initialSelectedPages, selectedPagesResolved} = useSelect( ( select) => { …. }, —–>[] <—– ); You declared the dependencies as an empty array, and empty arrays won’t change, so this hook won’t update when your attributes update because … Read more