Gatsby & WordPress - 3.4.5. - Render HTML Strings as Elements

by Jack Pritchard

Hey! This post's a little over two years old now, so some of what's here might be out of date. Still worth a read, but if anything really matters to you, it's worth double-checking against a newer source too.

When working with our WordPress GraphQL schema we will often encounter the issue of having to render an HTML string as HTML elements within our React application.

Instead of using the unpreferred method of setting the HTML string as innerHTML dangerously, we will parse the HTML string and detect for any relative anchor tags. Replacing those instances with the Gatsby 'link' component.