Hacker News new | ask | show | jobs
by dvcc 3267 days ago
I have no problem with stateful components, it was with this oddity:

   this.state = {
     value: this.props.value || '',
   }
1 comments

Standard React advice is that copying values from props to state is _usually_ a bad idea and should generally be avoided. It _can_ be useful in cases where you have something like an editor component that wants to allow updates to the values internally, only notify the parent when the edits are complete, and overwrite the edited values if the props change. The most common mistake in copying props to state is only doing it in the constructor, and forgetting to also do it in `componentWillReceiveProps`.

So, that snippet is actually valid - presumably they want to initialize the internal state value based on the corresponding prop, and use an empty string if it doesn't exist.

I don't disagree, it's just why place merit into an opinion that is poorly using a library(ies in this case). If I were to compare two libraries I wouldn't use the exception cases to show their differences - it's unhelpful and misleading.