Code techniques for handling dynamic data in the new(ish) world of blocks
summary
Walks through a working Parthenon plugin scaffolded with create-block, uses a PHP render callback to inject block HTML and JSON-encoded attributes, enqueues build/front-end.js via wp_enqueue_script and webpack, then mounts front-end React components (wp.element, WP Components) into a target div. Demonstrates passing attributes into JSX, and fetching live data from a custom REST route (fake calendar slots) with fetch/async — the demo renders the date picker, retrieves slots, and logs the response, so the approach actually works.
AI-written summary · about
chapters (10)
- 0:00Introduction and setup
- 4:03Dynamic data in blocks
- 8:46Plugin structure and registration
- 13:11Creating and using the block
- 17:49Running JavaScript on frontend
- 27:20Rendering React components
- 36:21Passing attributes to JavaScript
- 37:48Interactive API preview
- 48:23Fetching data via REST API
- 52:23Demo and conclusion
