466 karma · joined June 8, 2013
When you use strings that converts into javascript, e.g.
onChange="()=>this.toggleChecked(todoIndex)
then you lose out on all the static analysis tools that work on javascript, the language. Are there any existing tools that are going to tell you that this.toggleChecked
is undefined? I doubt it.Please embrace javascript, not crippled DSLs.
Another problem with what's written is that there's unnecessary state. In general it's best to figure out the minimal set of state needed to render the UI; everything else should be computed on the fly, directly in the render call (or refactored out into methods).
In this article, data and filteredData as state is unnecessary! The minimal state needed to describe the UI is the text to filter the data and the data itself which is from props. filteredData should be computed, not stored in state.
The text in the input box should always represent the state of the filter text, and the box itself can be used to update this state. This can be achieved with LinkedStateMixin[2].
1. https://facebook.github.io/react/tips/props-in-getInitialSta... 2. https://facebook.github.io/react/docs/two-way-binding-helper...
n % 1 == 0