Тёмный
No video :(

This is how I write cleaner react code - live refactoring a subscribers react project 

Web Dev Cody
Подписаться 227 тыс.
Просмотров 32 тыс.
50% 1

Just refactoring some code, this one was pretty fun to clean up.
My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets
------------
🤑 Patreon / webdevjunkie
🔔 Newsletter eepurl.com/hnderP
💬 Discord / discord
📁. GitHub github.com/codyseibert/youtube

Опубликовано:

 

12 сен 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@marcbaring3129
@marcbaring3129 Год назад
Appreciate this so much! Thanks for refactoring my messy react code haha! Feels good to learn while seeing your code getting refactored! As a beginner, I love how you explain every single line of code while being so chill. I guess refactoring my project was really a good way for you to make a video teaching about good code practices and how to write cleaner code. Definitely applying these new practices for my next project!
@WebDevCody
@WebDevCody Год назад
For sure man, it was fun refactoring this one
@qram04
@qram04 Год назад
Props for sending in your code. The most important thing in learning programming is to just build things and be own your mistakes and learn from them. Wish i had been better at that in the start of my career
@pesterenan
@pesterenan Год назад
These videos are so valuable. There is so much small errors that get compounded and we don't even stop to see if it can be improved. Nice one!
@__dev14
@__dev14 Год назад
Subscribed a few weeks ago and I really enjoy your videos. Your vibe is super chill and cozy. I also appreciate how open you are about the things you don’t know and have to improve, but that’s okay because that’s what a dev’s life is about. Happy coding ✨
@WebDevCody
@WebDevCody Год назад
Welcome to my channel! I’m glad you enjoy my vibe, that’s exactly what I’m going for, as if I’m sitting next to you teaching you some stuff
@hughlilly
@hughlilly Год назад
@@WebDevCody Totally agree with OP - great content, love the vibe! I think I just learned about 20 new things :D
@TheRcfrias
@TheRcfrias Год назад
Cool, it really helps to re-think what could be better and identify bad practices. I think a big limbo is understanding every time when to use what outside or inside the main function definition
@Wolfo70
@Wolfo70 Год назад
these videos are awesome man!
@Ca-rp7bv
@Ca-rp7bv Год назад
This is pure gold! Keep going!!
@SonAyoD
@SonAyoD Год назад
Awesome refactor, keep doing these!
@rujor
@rujor Год назад
The more React videos I see, the happier I am to have chosen Angular all those years ago 😄.. But great stuff 👍!
@hombacom
@hombacom Год назад
Great walkthrough. I would have category structure as a list of ID/name somewhere (no custom logic that depends on language), and result text as a state that seems to not be multiple things at once.
@k1mpman
@k1mpman Год назад
Didnt expect to learn about bem, most videos I watch use tailwind, bootstrap and so on but I love to make my own css. I'll definitely start using bem!
@WebDevCody
@WebDevCody Год назад
Checkout SMACSS, OOCSS, and BEM, Atomic CSS
@stercorarius
@stercorarius Год назад
nice tips with BEM, not heard of that before
@TheAditya64
@TheAditya64 Год назад
Why people don't use elements like header, main, section, article ? Why just div, div div ? Semantic HTML is a thing guys....
@RAM-im5lr
@RAM-im5lr 2 месяца назад
Soydev
@dosss_
@dosss_ Год назад
12:33 recreating the function (i.e. without useCallback) is fine here, as it’s almost negligible cost useCallback is useful for when you’re passing a function as a prop, and you don’t want its reference to change and cause a rerender
@WebDevCody
@WebDevCody Год назад
Ty!
@martindimitrov4696
@martindimitrov4696 Год назад
How come ? If function is not wrapped in useCallback, after data is being fetched and state is updated the function will get a new reference which will result in triggeting logic in useEffect again and again leading to memory leak.
@dosss_
@dosss_ Год назад
@@martindimitrov4696 true, probably much cleaner to just inline then
@adarsh-chakraborty
@adarsh-chakraborty Год назад
Damn, I have a similar project but it's messed up. I think i should start using react custom hooks now!!
@SeibertSwirl
@SeibertSwirl Год назад
Good job bub!
@agustinperez8700
@agustinperez8700 2 месяца назад
god refactor bro!
@lipun_panda
@lipun_panda Год назад
I think around 17:21 you were thinking about useEffect running on every rerender and calling fetch categories multiple times but when you pass an empty dependency array, the useEffect behaves like componentDidMount and runs only once. The reason behind this is useEffect runs when anything in the dependency array changes and since the dependency array is empty, nothing is changing so it runs only once. Now if you had a state called category and whenever that state updates i.e., the category changes you would want to rerun the useEffect to fetch questions regarding that category. In that case you’d put category in the dependency array.
@stylishskater92
@stylishskater92 Год назад
But when i use an empty dependency array it complains that i need to pass the function im calling in useEffect as a dependency... which then i have to turn the function into useCallback so the reference doesnt change on component rerender and triggers a rerun of the useEffect... am i misunderstanding something?
@gabrielalcantarabernardes8425
on 25:45 I prefer to setIsLoading(false) on finally rather than each step
@fromthefuture1238
@fromthefuture1238 Год назад
thank you
@guacamole4876
@guacamole4876 Год назад
21:38 /api/ can also be added to the BASE_URL string
@SamOween
@SamOween Год назад
15:05 I really liked the way that we used a hook to seperate the concerns of data fetching and displaying that data. Would it be overkill to have a container component that uses the useCategories hook which then passes the results as props into a dumb/presentational component to make it easier to perform component tests? That way, it would be a lot easier to mock and falls in line with Test-Driven Development principles. This has been the way I have found best so far. What do you think? @WebDevCody
@owenwexler7214
@owenwexler7214 Год назад
1:08 Tsah-tsee-kee
@slackergeek2007
@slackergeek2007 Год назад
Tzatziki is so good. Just use some pita bread to scoop it up. Try it one day.
@coldym
@coldym Год назад
I would lift state up in 36:47 to remove useEffect from SettingsCard
@carnath6
@carnath6 Год назад
Hey Cody, thanks for the refactoring video. Any chance you'd be willing to go over some of the shortcuts you're using on vscode?
@WebDevCody
@WebDevCody Год назад
I have a video on that
@carnath6
@carnath6 Год назад
@@WebDevCody I'll look for it thanks
@KyleKatarn145
@KyleKatarn145 Год назад
When you abstract the axios functions out to another class, would it be better practice to further abstract the axios call into its own helper function with the link as an input so that you can maybe change out say if you wanted to swap from axios into fetch in the future so that all your derived helper functions are only calling from one method instead of having to change up the axios call method in all of your other getContent functions?
@WebDevCody
@WebDevCody Год назад
You could do that, at the very least you could create a thin wrapper to make it easier to remove axios in the future.
@farhadjaman5580
@farhadjaman5580 Месяц назад
Can you share the repo? I want to follow along with you
@John-Dennehy
@John-Dennehy Год назад
Line 16-17 of Categories.js you use setError(error) instead of setError(err)
@WebDevCody
@WebDevCody Год назад
Good catch, I thought I fixed that later but maybe I missed it
@dosss_
@dosss_ Год назад
yea that’s why it was insisting you use useCallback, if you use the actual err var it would’ve been sweeet
@barringtonlevy1941
@barringtonlevy1941 Год назад
can you use .then and async/await in the same function? i thought it was one or the other, not both
@WebDevCody
@WebDevCody Год назад
Yes you can use both
@australianciggybatch7169
@australianciggybatch7169 Год назад
nice
@kemoboy
@kemoboy Год назад
at 13:59, the dependency array could've just been "categories", not "fetchCategories"?
@NightstalkerKK
@NightstalkerKK Год назад
what is he talking about with useCallback does anyone have reference doc or youtube that shows the problem?
@WebDevCody
@WebDevCody Год назад
What part of the video do I mention it? Maybe I can break it down
@sanjarmirakhmedov4016
@sanjarmirakhmedov4016 Год назад
Just put the fetchCategories inside the useEffect itself, as it's only used inside that effect, this way you won't have a problem with useCallback and dependency hell, also you broke the logic with that refactor lol=) it will now unexpectedly fire the effect once again if an error happens.
@WebDevCody
@WebDevCody Год назад
yeah, I think I accidentally put 'error' in the dep array because i called setError(error) instead of setErr(err). I agree, I should probably just move the function into the effect since it isn't used anywhere else, good feedback!
@sanjarmirakhmedov4016
@sanjarmirakhmedov4016 Год назад
@@WebDevCody This trick has actually changed my mind a lot when I got to it at some point, anyways keep up the good work and progress 🙌
@stylishskater92
@stylishskater92 Год назад
@@sanjarmirakhmedov4016 But what if you need to run multiple functions in useEffect? It feels long to have a very long useEffect body. Also, if you need to run 15 functions then having 15 separate useEffect calls also doesnt feel right... or is it?
@darelbvcr687
@darelbvcr687 Год назад
can i send you my project in react?
@sjoerdvermeijden
@sjoerdvermeijden Год назад
BEM is not pronounced as BIM lol sorry couldn't help myself, love the content!
@mastercode7851
@mastercode7851 Год назад
how can i send you my project to refactor?
@WebDevCody
@WebDevCody Год назад
Discord, no promises
@SirXtC
@SirXtC Год назад
8:00-8:47 code spliting the axios call its just to make it look nicer, it wont matter on the actual network tab, you can see every URL used in the project, all tokens, every payload too, if you are using a token or apikey, it will be shown to everyone who is using that page, the only way to hide it is serverside. even using environment variables wont hide any API keys, if its being used as an axios call in the frontend. unless you just meant to hide it from view in the code inside the project.
@WebDevCody
@WebDevCody Год назад
Yes I mean abstract it away from the component code. Idk what I said but I didn’t mean hide anything.
@SirXtC
@SirXtC Год назад
@@WebDevCody i most likely misunderstood
@uddinrokib7
@uddinrokib7 Год назад
Abstracting third party libraries from your code is to make your life easier when there is a major version change in the third party library that you are using.
@guacamole4876
@guacamole4876 Год назад
55:43 I don’t know why he uses Fragments when he has a div as a direct child
@WebDevCody
@WebDevCody Год назад
Idk either, you don’t need a fragment if you already return a single div
@benkatz8999
@benkatz8999 Год назад
I'm sorry but I had to stop watching after seeing you answer those trivia questions. What rock do you live under where you've never heard of Tandoori chicken lmaooo
@WebDevCody
@WebDevCody Год назад
Lol I don’t eat Indian food
@zwolof
@zwolof Год назад
use .finally instead of calling setIsLoading in both .then and .catch
Далее
Это реально работает?!
00:33
Просмотров 3 млн
Web Developer Portfolio - 9.5/10 (Front End, React)
11:54
Why Signals Are Better Than React Hooks
16:30
Просмотров 467 тыс.
JPEG is Dying - And that's a bad thing
8:09
Просмотров 57 тыс.
How I Write Clean Code in React
16:36
Просмотров 27 тыс.
Is this the perfect React app? - Code Review
11:02
Просмотров 39 тыс.
How I structure my next.js applications
23:19
Просмотров 24 тыс.
Cleaner Code: 3 Ways You Can Write Cleaner Code
7:41