I have a React element with a name attribute and child text, both of which are taken from the same value in props.
When re-rendering a React component with a different prop value, only the child text is updated, but the name attribute stays the same:
var Inner = React.createClass({
render: function () {
var name = this.props.name;
return ( <div name={name}>{name}</div> );
}
});
React.render(<Inner name="red"/>, document.getElementById('outer'));
// element is now <div name="red" data-reactid=".0">red</div>
React.render(<Inner name="green"/>, document.getElementById('outer'));
// element is now <div name="red" data-reactid=".0">green</div>
As you can see, after the second call to React.render, the name attribute is still red. (see http://jsfiddle.net/chyp9mxL/)
This problem can be resolved by adding a key={name} in the render function, but I don't see why I have to. Aren't keys only needed when we have multiple components? We only have one here.
React.render()...