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