Sure it's hard, but it's so worth it
I am actually going to release a really deep course on "React fundamentals" on Cosden Code to help
Join the waitlist cosdencode.ai
Sure it's hard, but it's so worth it
I am actually going to release a really deep course on "React fundamentals" on Cosden Code to help
Join the waitlist cosdencode.ai
So many developers try to avoid re-renders by using useMemo and useCallback, only to achieve nothing
Re-renders are good. It means you're seeing the updated data. This is what you want
If you have slow renders, then fix those in isolation as they come up
So many developers try to avoid re-renders by using useMemo and useCallback, only to achieve nothing
Re-renders are good. It means you're seeing the updated data. This is what you want
If you have slow renders, then fix those in isolation as they come up
Recently I saw a developer create a whole Zustand store with a bunch of state and functions, all to avoid passing one prop 3 layers deep
Prop drilling is not that bad. 3 layers is fine, especially if those components are only used once
Recently I saw a developer create a whole Zustand store with a bunch of state and functions, all to avoid passing one prop 3 layers deep
Prop drilling is not that bad. 3 layers is fine, especially if those components are only used once
Refs are so powerful and underrated in React. And they are not just for DOM elements
Refs allow you to store any value and read it without causing or waiting for a render
When you update a ref, unlike useState, the component doesn't re-render
Refs are so powerful and underrated in React. And they are not just for DOM elements
Refs allow you to store any value and read it without causing or waiting for a render
When you update a ref, unlike useState, the component doesn't re-render
Here's the rule: everything you use inside a useEffect, HAS TO go in the dependency array
If you don't, you WILL forget something and you WILL have bugs
E.g. having an onVisit(url) function but not calling it when url changes
Here's the rule: everything you use inside a useEffect, HAS TO go in the dependency array
If you don't, you WILL forget something and you WILL have bugs
E.g. having an onVisit(url) function but not calling it when url changes
Like we're doing in the example above
And this is actually officially recommended in the React docs
Weird huh?
Like we're doing in the example above
And this is actually officially recommended in the React docs
Weird huh?
This means that the JSX is not going to get updated in that render
React is going to start again on a new render from the top
This means that the JSX is not going to get updated in that render
React is going to start again on a new render from the top
Then, we have an if statement directly in the body of the component as its rendering, comparing prevCount and count
If they're not equal, we set prevCount to the count to sync them
Then, we have an if statement directly in the body of the component as its rendering, comparing prevCount and count
If they're not equal, we set prevCount to the count to sync them
Effect events are similar to refs. They let you see the latest values
Now, we never have to worry about dependency arrays ever again
Effect events are similar to refs. They let you see the latest values
Now, we never have to worry about dependency arrays ever again
We can create an effect event called onVisit and call that in the body of useEffect instead
Effect events do not need to be provided in dependency arrays, but they still see the latest values
We can create an effect event called onVisit and call that in the body of useEffect instead
Effect events do not need to be provided in dependency arrays, but they still see the latest values
The rules of hooks say that everything used inside of the body of useEffect has to go in the dependency array
So if we can't do that, what's the solution?
The rules of hooks say that everything used inside of the body of useEffect has to go in the dependency array
So if we can't do that, what's the solution?
With this code, when the numberOfItems changes, the event will fire even if the URL hasn't changed
This is probably not what we want
To fix it, we need to remove numberOfItems from the deps array
With this code, when the numberOfItems changes, the event will fire even if the URL hasn't changed
This is probably not what we want
To fix it, we need to remove numberOfItems from the deps array
There will be many courses on it, on React and frontend
I'm beyond excited! You can join the waitlist here: cosdencode.ai
There will be many courses on it, on React and frontend
I'm beyond excited! You can join the waitlist here: cosdencode.ai