-
registerComponent(String componentName, class|function component)
Register component so it's globally accessible.
import MyComponent from 'my-component'; registerComponent('MyComponentName', MyComponent);
note: Registered components are accessible in globally exposed
ReactRailsUJS
underreactComponents
property. -
getComponent(String componentName)
Shortcut for accessing registered component.
getComponent('MyComponentName');
-
createComponent(String componentName[, Object props])
Wrapper over React.createElement that creates ready to render component with props.
createComponent('MyComponentName', {foo: 'bar'});
-
renderComponent(String componentName, Object props, DOMElement container)
Wrapper over
React.render
andReact.createElement
. Renders component with given props into specified DOM element.var element = document.getElementById('my-element'); renderComponent('MyComponentName', {foo: 'bar'}, element);
-
react_component(String component_name[, Object props])
Creates DOM node with props as data attributes in rendered view so ReactRailsUJS can grab it and mount proper component.
<%= react_component('MyComponentName', MySerializer.new(my_data)) %>
note: Object will parsed to JSON. Be careful when passing rails models as props - all its data accessible after
.to_json
will be exposed as data-attributes. We strongly recommend using serializers to control it.