From d83238caf0c9b85f9c789c9f743657c875192a91 Mon Sep 17 00:00:00 2001 From: Dustin Schau Date: Fri, 28 Sep 2018 14:52:17 -0500 Subject: [PATCH] feat: get hot reloading working for js code snippets --- plugins/gatsby-transformer-home-example-code/gatsby-node.js | 3 +-- src/components/CodeEditor/CodeEditor.js | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/gatsby-transformer-home-example-code/gatsby-node.js b/plugins/gatsby-transformer-home-example-code/gatsby-node.js index d9659dfa..21a13eb1 100644 --- a/plugins/gatsby-transformer-home-example-code/gatsby-node.js +++ b/plugins/gatsby-transformer-home-example-code/gatsby-node.js @@ -1,6 +1,5 @@ const crypto = require(`crypto`); -// docblock goes here const createContentDigest = obj => crypto .createHash(`md5`) @@ -9,7 +8,7 @@ const createContentDigest = obj => // Store code snippets in GraphQL for the home page examples. // Snippets will be matched with markdown templates of the same name. -exports.onCreateNode = async ({node, loadNodeContent, actions}) => { +exports.onCreateNode = async ({actions, node, loadNodeContent}) => { const {createNode} = actions; const {absolutePath, ext, name, relativeDirectory, sourceInstanceName} = node; diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index e5ebb80c..0704bfa7 100644 --- a/src/components/CodeEditor/CodeEditor.js +++ b/src/components/CodeEditor/CodeEditor.js @@ -35,6 +35,10 @@ class CodeEditor extends Component { componentDidUpdate(prevProps, prevState) { if (prevState.compiled !== this.state.compiled) { this._render(); + } else if (this.props.code !== prevProps.code) { + this.setState({ + code: this.props.code, + }); } }