0

I have a react componente like this

var Task = React.createClass({
  render: function () {
    return (
      <div className="task" id={ this.props.task.uid }>
        <div className="header">
          <span>task #{ this.props.task.uid }</span>
        </div>
      </div>
      )
  }
});

and when a task is created, I add this task to the task list inside an create.js.erb

<% if @task.errors.any? %>
  $("#error-alert").removeClass('hidden')
<% else %>
  $('#task-modal').modal('hide')
  $('#tasks-list').prepend(React.renderToString(Task({ task: '<%= @task.to_react %>' })))
<% end %>

turns out that when the task component is prepended, he is prepended empty (just a box, without any text).
I tried <%= @task.to_react.to_json.html_safe %> and also had no success

My Task#to_react method:

def to_react
   {
     role: role,
     need: need,
     result: result,
     uid: uid
   }

end

1 Answer 1

1

Not that familiar with rails but unless it's doing some magic here you're embedding the object in a string.

Try

task: <%= ... %>

Instead of:

task: '<%= ... %>'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.