-
Notifications
You must be signed in to change notification settings - Fork 751
Closed
Description
Help us help you! Please choose one:
- My app crashes with
react-rails, so I've included the stack trace and the exact steps which make it crash. - My app doesn't crash, but I'm getting unexpected behavior. So, I've described the unexpected behavior and suggested a new behavior.
- I'm trying to use
react-railswith another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working. - I have another issue to discuss.
Issue
Props are currently camelized through a private instance method on React::Rails::ComponentMount:
https://github.com/reactjs/react-rails/blob/master/lib/react/rails/component_mount.rb#L51-L64
While this works for the initial rendering on a component, if the component needs to be re-rendered via update.js.erb, for example, the props have to manually mapped, keys have to be translated, or we need to tap into the existing private method:
// update.js.erb
ReactDOM.render(
React.createElement(ExampleComponent, <%= raw({
someLongKeyName: "value"
}.to_json) %>,
document.getElementById("example_component_id")
)Workaround
# application_helper.rb
def camelize_props(props = {})
React::Rails::ComponentMount.new.send(:camelize_props_key, props)
end// update.js.erb
ReactDOM.render(
React.createElement(ExampleComponent, <%= raw(camelize_props({
some_long_key_name: "value"
}.to_json) %>,
document.getElementById("example_component_id")
)danielma
Metadata
Metadata
Assignees
Labels
No labels