Don't Use React Context!! Use This instead

Don't Use React Context!! Use This instead

CoderOne

10 месяцев назад

25,361 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@yolla_4
@yolla_4 - 19.11.2023 15:03

thanks for this video

Ответить
@lilbahr
@lilbahr - 08.11.2023 13:03

How does this relate to: "This Context API Mistake Ruins Your Whole React App (All Components Re-Render)" by ByteGrad? Doesn't that solve the issue?

Ответить
@samnayakawadi
@samnayakawadi - 18.09.2023 16:53

So, Its better to go with redux. Subscribed btw.

Ответить
@Gangbuster74
@Gangbuster74 - 08.09.2023 15:43

Which vs code theme u are using @coderone please reply

Ответить
@airixxxx
@airixxxx - 04.08.2023 04:22

The only reason it's re rendering is because you put the state on the App component, that's what's re-rendering. This is not a Context problem, it is a logic problem, if you create a separate file with the context of the app and pass it to its children you wont get re-renders.

Ответить
@emreq9124
@emreq9124 - 29.07.2023 02:01

Can you provide sandbox to try myself?

Ответить
@patrickconrad396
@patrickconrad396 - 17.07.2023 17:14

I saw someone using context with refs and a pup sub system. that may be the new approach for me. Using refs stopped the propagation of changes while subscribing to specific stores allowed for only the specific component to update its own state with the new info and make the change there.

Ответить
@DigitalMonsters
@DigitalMonsters - 13.07.2023 17:22

I decided to try context a couple months ago for the first time on a work project and im not sure i really understood it but shoe horned it in anyway and got everything working or so i thought, now nearing the end of a project and getting all these unintended re-renders from parent state changes Q_Q no idea how to fix it..

<NavigationContainer>
<AuthProvider>
<DatabaseProvider installedAppVersion={currentVersion}>
<StorageProvider>
<ContentProvider>
<GeoLocationProvider>
<PaperProvider theme={theme}>
<GestureHandlerRootView style={{flex: 1}}>

Ответить
@mbertufpv
@mbertufpv - 09.07.2023 11:59

You Just avoid that using the pattern provider and stop using useContext like a junior dev

Ответить
@judegao7766
@judegao7766 - 09.07.2023 06:43

do you have any resource that deep-dives the last bit around putting console.log inside the useEffect vs directly in the function body - you mentioned something about concurrent rendering - does it mean that React concurrent rendering would re-execute your function but it may not actually re-render (because useEffect is not called)? but why?

Ответить
@aidanwalker7136
@aidanwalker7136 - 08.07.2023 13:03

can I have the github repo?

Ответить
@johnhershberg5915
@johnhershberg5915 - 05.07.2023 13:38

Only issue I have with this video is you're saying "re-render" often, but that's not actually what's happening. A functional component's function being invoked doesn't mean the DOM was updated. If a function call results in the DOM being updated that's a re-render. This is just React calling the function to see if the DOM needs to be updated, which it doesn't, so the expensive part of redrawing the DOM gets skipped.

That said, it's still extra work that's being done pointlessly. And depending on what you have going on in your components it could be a major performance hit. So it's worth keeping this in mind, and I'll take note of this context issue from now on! Thanks!

Ответить
@najlepszyinformatyk1661
@najlepszyinformatyk1661 - 04.07.2023 19:57

jotai is much better choice

Ответить
@StefanoV827
@StefanoV827 - 04.07.2023 15:57

Context is not a global state manager. React describe it as another (smartest) way to pass props to children. So it's normal that every child will refresh changing params to the context.
Thats why redux exists.

Ответить
@long-live-linux
@long-live-linux - 04.07.2023 14:56

Web frontend articles are filled with "use this instead"

Ответить
@testchannel3265
@testchannel3265 - 03.07.2023 21:45

dont use react

Ответить
@moonyyy9093
@moonyyy9093 - 03.07.2023 17:08

redux-toolkit uses a Provider as well, I remember this won't have a rerender on the entire sub components, corret me if I'm wrong please.

Ответить
@crim-son
@crim-son - 03.07.2023 12:47

Honestly, i think I'll just stick with using context the way it is, React is fast, no cap.... I'll only resolve to this if i have noticable performance issues, and not when my component is rendering just a little more than normal

Ответить
@JS_Jordan
@JS_Jordan - 03.07.2023 12:44

zustand!

Ответить
@kevinwang9495
@kevinwang9495 - 03.07.2023 12:20

wrap the component with memo() ?

Ответить
@wasaabbi
@wasaabbi - 03.07.2023 11:48

Why you put log with render inside useffect? It should log info being standalone console log anywhere in the body of component

Ответить
@iCodeArtisan
@iCodeArtisan - 03.07.2023 10:39

Personally, I think Zustand is a perfect client-side state management library

Ответить
@ronaldpaek
@ronaldpaek - 03.07.2023 09:23

I thought that's how context is normally supposed to work? I don't think Context actually causes rerenders but since you're declaring the state and passing that into Context anytime the state changes it will cause the whole context wrapper to re-render?

Ответить
@kevinat71
@kevinat71 - 03.07.2023 09:10

its okay, but i prefer zustand, jotai or rtk

Ответить
@laxmiprasanna4092
@laxmiprasanna4092 - 03.07.2023 07:49

Redux ?

Ответить
@luanmaffra9324
@luanmaffra9324 - 03.07.2023 06:32

I already used it with RTK query. Make selectors. Same approach

Ответить
@rishiraj2548
@rishiraj2548 - 03.07.2023 06:31

👍🙏

Ответить
@lee2k137
@lee2k137 - 03.07.2023 05:40

it reminds me in VueJS simply provide("key", "value") and inject("key"), it's blazingly fast 🙄

Ответить
@anasouardini
@anasouardini - 03.07.2023 05:39

useContext is just another useless React hook.
I personally just use Jotai, matter of fact, most of the time I just write Jotai myself. If you've never done that yourself, you might think it's complex but it's only around 10 lines of code that you only write once throughout your app.

Ответить
@vladislavpavlyuk5531
@vladislavpavlyuk5531 - 03.07.2023 05:04

What the plugin prints before functions "Ask Easy code Explain ... "?

Ответить