Created
October 5, 2019 21:09
-
-
Save danott/6fadcb5ac8dba6ec539f8bdafceaa123 to your computer and use it in GitHub Desktop.
A minimal Rails helper for rendering a React component into the DOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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