4 ms·
This comment is sure to prove controversial among the more rigorous React followers, but i disagree with the anti-pattern claims. Having built a startup on Back
by liquidise 10y ago
This comment is sure to prove controversial among the more rigorous React followers, but i disagree with the anti-pattern claims. Having built a startup on Backbone and React, i find that referencing `this.state` is a fine way to handle data shifts in our views.
While i have read the oft-presented reasons for not using `this.state`, the arguments feel more academic to me than being based in practical examples. Your milage may vary, but in my experiences `this.state` is one of the more powerful features in React. To me, removing read access to component state also removes one of the more compelling reasons to include React into your codebase at all.
- acemarke 10y agoYep, using something like Redux or MobX absolutely does not mean "no React component state ever". There's definitely use cases for all of the above. Dan Abramov has tried to make that point repeatedly, and I made sure to put that viewpoint into the Redux FAQ ( http://redux.js.org/docs/FAQ.html#organizing-state-only-redux-state http://redux.js.org/docs/FAQ.html#organizing-state-only-redu... ).
- tengbretson 10y agoTo be clear, I wasn't meaning that use of local state was an anti-pattern in itself. I only meant that dumping all of the state of a wrapper component into the child should be avoided. Ideally, the complexity of the data in the props of a component should lessen the closer one gets to a leaf in the view tree.