JavaScript for WordPress Forums Gutenberg Development Inspector controls inside dynamic block Reply To: Inspector controls inside dynamic block

#45036
Zac Gordon
Keymaster

Okay, so this line here is actually taking props and destructuring it.


  } )( ( { attributes, posts, className, isSelected, setAttributes, RadioControl } ) => {

You could instead just let props be passed down instead of destructuring it here and update your other code to props.posts etc or you can just pass down the specific things you need into the inspector rather than passing all of props.

The other thing to mention here is that if changes in the inspector settings change the API request it will redraw the entire block and inspector, which is annoying.

If you look at the core latest posts block you’ll see its much more complex. I have talked with a core dev about how to improve this and will likely have an example not using withAPIData and rather making the API call using some other options they are working on adding. This isn’t ready quite yet, but you can look at this example from V1 of the course for an alternative approach to withAPIData:

https://github.com/zgordon/gutenberg-course/tree/v1/jsforwp-blocks/blocks/examples/13-dynamic-alt

Hope that helps!