1.0.2 • Published 4 years ago

isoblock v1.0.2

Weekly downloads
1
License
GPL-2.0
Repository
-
Last release
4 years ago

Using ReactDOM.hydrate() For Isomorphic Gutenberg Blocks

An Isomorphic Gutenberg Block uses the same React components for its "view" no matter where it is being displayed -- editor, front-end or a client decoupled from WordPress.

Me

This plugin is an example of a block that provides a form with one field. The block has a UI to set the defult value of the form. The form's HTML is saved to post content.

When a post with this block is loaded in the front-end, and the plugin is still active and JavaScript is enabled, then ReactDom.hydrate() is used to mount an app on the same DOM element. This allows the form to become interactive and have state manged by React, when possible. If the JavaScript isn't there, its just HTML.

Why?

WordPress (or some other CMS) is used to create HTML. If the client has JavaScript enabled, then the JavaScript enhances the HTML. The HTML is not dependent on the JavaScript. If the plugin is deactivated, the from it outputs should still work.

Also, its way simpler than anything else I tried. The only PHP is the block registration. This should be usuable, very easily outside of WordPress.

Notes

Development

  • Clone
    • git clone git@github.com:Shelob9/isoblock.git && cd isoblock
  • Install
    • yarn
  • Start
    • yarn start
  • Build For Production
    • yarn build
  • Run Unit Tests
  • Run e2e Tests
    • yarn test:e2e
    • Must insall local dev environment first.

Local Development

A local development server is included. It requires Docker and Docker Compose and is 95% copypated from WordPress core's local environment

  • Start server and echo URL
    • yarn start:env