4 ms·
A poorly done React component (mixing props and state?) and what looks to be a poorly done Vue component (with some jQuery lib thrown in?), are the basis of the
by dvcc 9y ago
A poorly done React component (mixing props and state?) and what looks to be a poorly done Vue component (with some jQuery lib thrown in?), are the basis of the opinion? Seems weird.
- IanDrake 9y agoYeah, pick any framework that you don't know how to use properly, drop it for another framework that you don't know how to use properly, write a post on medium about it, repeat.
- jrs95 9y agoMight as well put a link to your e-book in it too, so you can make money when you get on the front page of HN.
- rhinoceraptor 9y agoYep, I think a lot of a confusing parts of React components is state and ES6 classes. Luckily, you don't actually have to use those, React really shines (IMO) when you write stateless components, using ordinary functions. const MyList = props => ( <ul> {props.list.map((item, index) => <li key={index}>{item}</li>)} </ul> ); ... <MyList list={[ 'item1', 'item2', 'item3' ]} />
- dvcc 9y agoI have no problem with stateful components, it was with this oddity: this.state = { value: this.props.value || '', }
- acemarke 9y agoStandard 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.
- dvcc 9y agoI 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.