Skip to content

Instantly share code, notes, and snippets.

@pashagray
Last active March 6, 2019 16:57
Show Gist options
  • Save pashagray/df4367df956a37d8a057488e1b225595 to your computer and use it in GitHub Desktop.
Save pashagray/df4367df956a37d8a057488e1b225595 to your computer and use it in GitHub Desktop.
module ComponentHelper
def react_component(name, props: {})
content_tag(:div, nil, id: name, data: { props: props.to_json, handler: "react" })
end
document.addEventListener("turbolinks:load", () => {
const tags = document.querySelectorAll("[data-handler=\"react\"]");
[].forEach.call(tags, (tag) => {
const data = humps.camelizeKeys(JSON.parse(tag.getAttribute("data-props")));
const componentName = tag.getAttribute("id");
const Component = apps[componentName];
ReactDOM.render(<Component {...data} />, tag);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment