You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReactfrom'./stdlib'importReactDOMfrom'react-dom'// Import react componentimportCategoryTreefrom'./category-tree'classApp{constructor(){// Register as part of global.App.Componentsthis.Components={
CategoryTree
}this.initialize()}// Create an event listener on page load to auto-mount for each div[data-component="<Component>"]initialize(){$(document).on('turbolinks:load',()=>{$('[data-component]').each((index,node)=>{consttarget=$(node)constprops=target.data('props')constcomponentName=target.data('component')constComponent=this.Components[componentName]if(Component){ReactDOM.render(<Component{...props}/>,node)}else{throw`Couldn't find component ${componentName} in App.Components`}})})}}
In View
= form_for @changeset, @action, fn f ->.field.control# Create the div[data-component="CategoryTree"data-props="{\"name\": \"resource[category_tree][]\", \"placeholder\": \"Product category\"}"] using the helper so that autocmount script can detect the component and mount it
= component "CategoryTree", name: f.name <> "[category_tree][]", placeholder: "Product category".field.control
= text_input f, :name, class: "input", placeholder: "Product name"