Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A minimal Rails helper for rendering a React component into the DOM
module ReactHelper
def render_react_component(component:, props: {}, dom_id:)
<<-REACT_DOM_RENDER.strip_heredoc.squish.html_safe
ReactDOM.render(
React.createElement(#{sanitize(component)}, #{raw json_escape(props.to_json)}),
document.getElementById("#{sanitize(dom_id)}")
);
REACT_DOM_RENDER
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.