Last active
March 6, 2019 16:57
-
-
Save pashagray/df4367df956a37d8a057488e1b225595 to your computer and use it in GitHub Desktop.
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 ComponentHelper | |
def react_component(name, props: {}) | |
content_tag(:div, nil, id: name, data: { props: props.to_json, handler: "react" }) | |
end |
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
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