7 React Lessons I Wish I Knew Earlier

  Переглядів 41,571

Code Bootcamp

Code Bootcamp

День тому

Join the Bootcamp: reactbootcamp.dev
Chapters:
0:00 - React State Must Be Immutable
1:26 - Don't Use State for Everything
2:46 - Derive Values Without State
3:34 - Compute Values Without Effects
4:10 - Keys Should Actually Be Unique
5:00 - Don't Leave Out Dependencies
5:58 - Use useEffect Last
7:07 - Conclusion

КОМЕНТАРІ: 54
@TheCodeBootcamp
@TheCodeBootcamp 11 днів тому
Correction (1:21) - First put the returned array from users.concat(newUser) in a new variable (i.e. newUsers). Then pass it to setUsers: setUsers(newUsers).
@Ayoubased
@Ayoubased 10 днів тому
i need to learn to read pinned first lol, beautiful video
@incarnateTheGreat
@incarnateTheGreat 10 днів тому
You beat me to it. Haha
@dvillegaspro
@dvillegaspro 9 днів тому
Using indexes as keys is not always a bad idea. If the set of items is known and never changing, there’s no reason you shouldn’t be able to use the index. It may be an anti-pattern in most cases but if you know when it is fine to use, just keep that in mind and do it.
@mustafawagih3429
@mustafawagih3429 8 днів тому
Well that's what I thought. Then I found myself using them in multiple positions in the same app (rendering more than one list using indexes as keys). And I had that warning then a bug that it failed to render properly. There's no written rule that you can't, but only do it if you're doing it only once through the whole app.
@tianyili6336
@tianyili6336 7 днів тому
@@mustafawagih3429Well, technically, you can. According to the definition of “Unique” - A key cannot be identical to that of a sibling component.
@sandunlasantha
@sandunlasantha 4 дні тому
Use ESLint and it would tell if the index is "OKAY" for the key or not
@coldicekiller1352
@coldicekiller1352 6 днів тому
its important to know that UseEffect runs TWICE after mount, but only on dev enviroments with strict mode on. I learned that after hours of debugging...
@darkwoodmovies
@darkwoodmovies 5 днів тому
For the "Keys Should Actually Be Unique" part, the purpose of this is list ordering. E.g. if you use a non-data-derived `index` as the key and the list order changes, the renderer won't know and it will not update correctly. If your list is not changing order, it's fine to use an index. Also, it only needs to be unique per parent - so you can e.g. have identical keys in two separate lists rendering as long as those lists have a different parent.
@gmg15
@gmg15 8 днів тому
5:51 i don’t recommend adding count to dependency array in this case.. as we can always use the previous value of the state inside setState and use that instead of directly using count
@janglad9136
@janglad9136 10 днів тому
6:41 I agree a simple fetch call in a useEffect is a naive approach and Tanstack query is great, however how do you think they implement this under the hood? Also using useEffect. Much in the same way it also starts requesting the data after the component renders.
@TheCodeBootcamp
@TheCodeBootcamp 4 дні тому
Correct, Tanstack Query doesn't fix all the problems of data fetching in React. It does have patterns like prefetching and suspense mode, however, which allow you to render-as-you-fetch. Every pattern has its tradeoffs.
@t_himmel6524
@t_himmel6524 2 дні тому
i already know all of this right now, but i wish i saw this video 2 years ago. Btw thank you so so much. Keep it up ! Peace
@ViniciusCerqueiraBonifacio
@ViniciusCerqueiraBonifacio 7 днів тому
Blowing app your project with extra libraries it is not good either. You do not really need, for instance, React Query to perform fetching data unless your case is very specific.
@SahilBhosale08
@SahilBhosale08 11 днів тому
Insightful💡
@user-kg6bk5mv9g
@user-kg6bk5mv9g 9 днів тому
pleas manke this types of vlideo more it actualy help to understand concept very great
@farid9323
@farid9323 8 днів тому
Love the tips here. Even an experienced dev can learn some things. But, I think useEffect is getting a bad rap. React was originally designed to fetch data after a component is rendered, so you'll always have some type of loading state, regardless of the library used. I wouldn't necessarily call that a "bad" UX. If you need the data earlier, then SSR is the way to go.
@TheCodeBootcamp
@TheCodeBootcamp 4 дні тому
If I'm using Next.js with app router, I like fetching data on the server in a React Server Component. If I need something more complex and across client components, I like Tanstack Query. I think each choice has its tradeoffs.
@detaaditya6237
@detaaditya6237 8 днів тому
Idk how I feel about "just use dedicated hooks to fetch data like swr, react query, or other library." It's alright to make the code work for now, but we introduce vendor lock-in to the project, a haunting tech debt that will lead us to long hours in the long run. However, I also agree that we shouldn't freely use the clunky-ass, hard to understand useEffect. To mediate this problem, I would introduce a context that contains the interface of "useDataFetcher," which is used by the components. The implementation is decided once at the top of the component tree, and this is where we the vendor hooks like swc and react-query are passed. It's not a perfect solution, as there is an extra layer of indirection now between the components and the vendor hooks, making it overkill for small projects. However, it will ease the whole process of migrating from one library to another.
@TheZayzoo
@TheZayzoo 11 днів тому
A video on suspense 👀?
@thefungigg7709
@thefungigg7709 11 днів тому
The example at 1:21 doesn't work as well, you are not calling setUsers with the new array created from the concat metod so that example wont do anything just like the faulty example. To solve it use the result from the concat method as the argument in setUsers :)
@TheCodeBootcamp
@TheCodeBootcamp 11 днів тому
Thanks for catching that. Missed that in the edit. The spread operator example is correct though. Check my pinned comment
@incarnateTheGreat
@incarnateTheGreat 10 днів тому
These are great! Thanks! Also, this feels like an advert for React Query. No complaints, though. ;)
@LokeshKumar-tk7ri
@LokeshKumar-tk7ri 11 днів тому
We need more tutorials about DSA
@tomashubelbauer
@tomashubelbauer 6 днів тому
The thing about not using indexes for keys flat out is a bit silly and you're doing yourself a disservice if you take it at face value. This tip is very commonly shared as an axiom, but it is really not. In many cases, indexes are perfectly safe as keys, especially when the array you're rendering won't change or it will only grow at the end but not shuffle or grow at the beginning / in the middle.
@ColaKingThe1
@ColaKingThe1 6 днів тому
That was a good video I liked it
@selectronm2920
@selectronm2920 11 днів тому
life is much easier with svelte
@JakeLuden
@JakeLuden 9 днів тому
Life is much easier when you just use react the way you’re supposed to use react
@sikritidakua
@sikritidakua 9 днів тому
rich harris is the goat
@mayurpatel6657
@mayurpatel6657 11 днів тому
Best explanation I have ever seen for React.❣
@ArchNpm
@ArchNpm 11 днів тому
hi can u make a vid like this on NextJs
@leelacreations
@leelacreations 5 днів тому
Could you please create a video on JavaScript Data Structures and Algorithms
@muhammadshafain3529
@muhammadshafain3529 10 днів тому
You seriously are very underrated.
@harsh_g2543
@harsh_g2543 10 днів тому
what about fetching data in server side using nextjs and server actions
@TheCodeBootcamp
@TheCodeBootcamp 4 дні тому
I'll do some Next.js videos to cover that
@KanishqSunil
@KanishqSunil 11 днів тому
Honestly, this person produces some of the cleanest videos on React concepts. I am amazed how he makes the videos look simple yet packs it with quality information. Keep it up 🫡
@leeroyjenkns5182
@leeroyjenkns5182 7 днів тому
2:38 why shouldn't you use states for stuff that needs to be rendered tho Is it purely because of it's async nature or what
@udaym4204
@udaym4204 6 днів тому
next video on next js Thanks
@ecvetanov
@ecvetanov 10 днів тому
State must be immutable ... unless you are using a state management tool like mobx
@mohamedalkhyat3284
@mohamedalkhyat3284 9 днів тому
Man, you don't even speak my language and I understood every word you said, thanks
@ryanlog
@ryanlog 8 днів тому
nothing will happen at 1:14 either lol
@TheCodeBootcamp
@TheCodeBootcamp 4 дні тому
Typo on my part. See the pinned comment
@hwapyongedouard
@hwapyongedouard 10 днів тому
same bro , immutable mutable 🤷‍♂🤷‍♂🤷‍♀🤷‍♀😂😂
@truthsayer9534
@truthsayer9534 10 днів тому
JavaScript is the Wild West, thus the large number of frameworks people write to make JavaScript more usable.
@The-Funk35
@The-Funk35 7 днів тому
I really don't understand why immutability was pushed so hard with React. It's JavaScript. It's single threaded. It can only perform a single action at a time. What race condition are we protecting against exactly?
@anxpara
@anxpara 5 днів тому
Number 8: don't use react. The year is 2024, there are better options available
@dereksniper
@dereksniper 4 дні тому
Nextjs? Lol
@IlyaVelo
@IlyaVelo 3 дні тому
Angular
@chrisrock219
@chrisrock219 21 годину тому
​@@dereksnipermumps
@jonashansen2512
@jonashansen2512 10 днів тому
R19 use(…) hook & ;)
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Переглядів 275 тис.
Web Developer Roadmap (2024) - Everything is Changing
25:02
ByteGrad
Переглядів 201 тис.
ДРУГА РЕПЕТИЦІЯ alyona alyona та Jerry Heil на сцені Євробачення-2024
00:34
Євробачення Україна | Eurovision Ukraine official
Переглядів 133 тис.
😱СНЯЛ ФИКСИКОВ НА КАМЕРУ‼️
00:35
OMG DEN
Переглядів 1,3 млн
Лизка заплакала смотря видео котиков🙀😭
00:33
Why Great Developers DON'T Create Content (and a lesson to learn)
6:56
React Native Bridgeless Mode for Dummies
6:43
Oscar Franco
Переглядів 1,6 тис.
Intro to re-renders - Advanced React Course, Episode1
7:07
Developer Way
Переглядів 18 тис.
The cloud is over-engineered and overpriced
14:39
Tom Delalande
Переглядів 87 тис.
The best (and worst) types for storing money in PostgreSQL
11:37
Dreams of Code
Переглядів 36 тис.
ALL React Hooks Explained in 12 Minutes
12:21
Code Bootcamp
Переглядів 21 тис.
Testcontainers have forever changed the way I write tests
12:11
Dreams of Code
Переглядів 75 тис.
Why You’ll WASTE The Next 3 Years…
6:06
Travis Media
Переглядів 164 тис.
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Переглядів 74 тис.
Subscribe for more!! #procreate #logoanimation #roblox
0:11
Animations by danny
Переглядів 3,7 млн
Infrared Soldering Iron from Cigarette Lighter
0:58
ALABAYCHIC
Переглядів 1,8 млн
Как установить Windows 10/11?
0:56
Construct PC
Переглядів 1,4 млн
Тестируем Gravis Ultrasound... ну почти.
48:18
Дмитрий Бачило
Переглядів 17 тис.