Closed pesterhazy closed 8 years ago
Seconded. Technically it works, but definitely not a good practice. (Also, the Lesson 10 link is actually still changing state, not _props.)
@pesterhazy You're right, but those links both point to the same file/line and it seems to me only the first time it's the right link.
@kay-is, sorry about that. The second link is https://github.com/kay-is/react-from-zero/blob/master/10-example-app.html#L32
function TaskList(props) {
// Print the first element bold
props.children[0] = <b key={0}>{props.children[0]}</b>
return <ul>{props.children}</ul>
}
My understanding is that a component should not mutate its own children in this way.
✨
Great tutorial!
Some example could be more careful about mutating state. For example, https://github.com/kay-is/react-from-zero/blob/master/10-example-app.html#L93 updates
this.state tasks
directly. A better approach would be to clone the array before mutating. (It doesn't matter in this particular example, but a tutorial should follow best practices.)Similarly, https://github.com/kay-is/react-from-zero/blob/master/10-example-app.html#L93 changes the props directly, which is a big no-no with React.
I may be wrong though. I'm not a React expert, after all I'm reading a tutorial on React.