reactjs / reactjs/react.dev

We have hooks, then still do we use Container components and Presentational components?

Offen
#2,819 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

discussion
Vorherrschende Sprache
JavaScript
Sterne
11.8k
Forks
7.9k
Ø Merge
1 T. 11 Std.
Gemergte PRs (30 T.)
11

Beschreibung

I think it is a bit confusing and maybe a doc or writing can explain the situation.

After we have hooks, do we still design our app into Container components and Presentational components? (Does it mean we should not divide up our app design into containers and presentational components?)

Or does it simply mean: in the past we use class components as containers with states, and function components as presentation components, and now we can use function components as both containers and presentational components, and the recommendation is still to divide our app design into containers and presentational component?

In the past, we can simply use class components ONLY and we could still divide our app design into containers and presentational components. So function component having state doesn't change that situation... the question is more like should we now still divide our app design into containers and presentational component? So nowadays we could still make container components using function components, and then, make presentational components and use function components to do that, and strictly do not use any hooks in them, because then they become stateful and therefore not just "presentational".

I think the short version of the question is: even with function components able to use states, should we still divide up our app into components that have states, and components that strictly do not have states and like "pure function" to present data?

@gaearon

https://stackoverflow.com/questions/60593403/for-reactjs-how-is-the-change-from-using-container-components-and-presentation

In the past, in ReactJS, one way was to divide our components into Container components and Presentational components, and even Dan Abramov wrote a note about it not any more the case if we can use Hooks now.

How should it be done now — how does Hooks solve the problem?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies den Issue-Text zusammen mit der verlinkten Stack Overflow-Frage und der Notiz von Dan Abramov. Als erledigt gilt die Erstellung einer fokussierten Erklärung für die React-Dokumentation, die beantwortet, ob Hooks die Empfehlungen zu Container-/Presentational-Komponenten ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, react
Bereich
documentation, frontend
Issue-Typ
Dokumentation
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.