Skip to content

Instantly share code, notes, and snippets.

@ryanwelcher
Created November 21, 2019 15:47
Show Gist options
  • Save ryanwelcher/dde2c52f28f6c6a2bfc958b220ed3410 to your computer and use it in GitHub Desktop.
Save ryanwelcher/dde2c52f28f6c6a2bfc958b220ed3410 to your computer and use it in GitHub Desktop.
const { Component } = wp.element;
const { ServerSideRender } = wp.components;
const { BlockControls, InnerBlocks } = wp.blockEditor;
import LivePreviewButton from '../../components/live-preview-button';
class EditComponent extends Component {
constructor(props) {
super(props);
this.state = { preview: false }
}
render() {
const { attributes, clientId, name } = this.props;
return (
<>
<BlockControls>
<LivePreviewButton
clientId={ clientId }
onChange={ preview => this.setState( { preview } ) }
/>
</BlockControls>
{ this.state.preview ? (
<div>
<ServerSideRender
block={ name}
attributes={ attributes }
/>
</div>
) : (
<>
<InnerBlocks/>
</>
)}
</>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment