React UseContext

Veröffentlicht am: 15 August 2022
auf dem Kanal: A shot of code
3,503
148

Prop drilling in React can be nightmare at times, useContext comes our rescue and allows us to access state from anywhere in the hierarchy.

By creating a Context and wrapping our top level component in this context with context.provider we can set the 'value' on this component to be our state.

Then in lower level components we simply import the Context and call useContext to retrieve the same state which can then be used.


Auf dieser Seite können Sie das Online-Video React UseContext mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer A shot of code 15 August 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,503 Mal angesehen und es wurde von 148 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!