Use case question regarding "You Probably Don't Need Derived State" article
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 11.8k
- Forks
- 7.9k
- Ø Merge
- 1 T. 11 Std.
- Gemergte PRs (30 T.)
- 11
Beschreibung
Hello,
I just finished reading: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html and at the bottom of the article it states:
It is also worth re-iterating that getDerivedStateFromProps (and derived state in general) is an advanced feature and should be used sparingly because of this complexity. If your use case falls outside of these patterns, please share it with us on GitHub or Twitter!
My question regards complex components like Datatables which take in many arguments and which allow developers to externally change things about the table. For example, I may setup a table like this:
var options = {
sortOrder: {field: "name", direction: "desc"},
}
<Datatable options={options} data={data} />
Internally the table allows users to change the sortOrder by clicking column headings. It manages to do this because it has it's own internal state which it derived from the input props. But lets say I want to change the sortOrder outside of the table.
One way to do this would be to change the options object and have the table re-render, it would then derive the sortOrder value from the props if present and use this for it's internal state. For table properties that aren't on props, the table would keep using it's internal state.
My question is - is this a good way of doing this, or is there a better way where state isn't derived from props? Comonents like a Datatable are very large and many of the properties should be uncontrolled, but there are certain properties that developers will sometimes want to control. Is this a good use case for using derived state?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lies zunächst den verlinkten Artikel „You Probably Don't Need Derived State“ und das Datatable-Beispiel in diesem Issue erneut. Ermittle, ob der beschriebene Mix aus extern gesteuertem und intern verwaltetem sortOrder durch den Artikel abgedeckt ist; als erledigt gilt eine dokumentierte Antwort oder eine klar abgegrenzte Dokumentationsänderung.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, react
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100