How I Write Clean Code in React

  Рет қаралды 22,925

Cosden Solutions

Cosden Solutions

Күн бұрын

Check Out Brilliant → brilliant.org/CosdenSolutions
🚀 Project React → cosden.solutions/project-react
Join The Discord! → discord.cosden.solutions
VSCode Theme | Font → Material Theme Darker | Menlo, Monaco "monospace"
In this video I will show you how I write clean code in React. I will show you my mindset, how I approach a problem, and how I break it down into multiple small parts to make it manageable and scalable. Through this video you will learn how to write better React code yourself, and become a better React developer!

Пікірлер: 65
@johndevnoza4223
@johndevnoza4223 Ай бұрын
as a begginer one, im doing this by habbit and i was scared if it was overkill or not. now i feel happy!
@sachityadav4141
@sachityadav4141 Ай бұрын
This was Needed 😀 ThankYou, i was having anxiety seeing lots of styling classes in return of every component
@dr_jacko
@dr_jacko Ай бұрын
This is a good start, but in general I would prefer to abstract fetch away a step further than hooks or components and you also need to handle loading and error states with your async calls. As an example, create a UserProfileRepository and UserProfileService classes which have functions for CRUD on UserProfiles. Use the singleton pattern on these classes and keep them in a context where it is required in the app.
@vladanisov1689
@vladanisov1689 24 күн бұрын
definitely the best approach for this kind of scenario!
@mulengachitalima7695
@mulengachitalima7695 Ай бұрын
Awesome video.. Really appreciate how you always adhere to SOLID principles in your videos
@user-be3ri8gf1p
@user-be3ri8gf1p Ай бұрын
Perfect timing, just wanted to learn about those :D
@hooooman.
@hooooman. 10 күн бұрын
A beginner here, this approach definitely makes our code more clean. but my doubt is, say if we are building a little advanced/complex project, the same approach makes too many folders and files ?
@sontranvan5348
@sontranvan5348 29 күн бұрын
Simple, effective tips that are easy to learn and apply. Thank you for sharing your knowledge!!!!
@gherardivictor
@gherardivictor Ай бұрын
Good quality and valuable content, thanks
@carloseduardomagalhaespere5112
@carloseduardomagalhaespere5112 Ай бұрын
Thank you for another great video! I've been learning a lot here! One question: Why do you prefer to use type instead of interface in the props definition? 🤔
@fanespratama
@fanespratama Ай бұрын
Take a note that when you use the custom hook with useEffect in more than one file, the useEffect will run more than once, so keep one custom hook for every layout/component (let say one for user list, one for user details). If not, just move the useEffect outside the custom hook
@MohamedRabi
@MohamedRabi 26 күн бұрын
Thank you for the fantastic content!
@tunde6159
@tunde6159 15 күн бұрын
Such good tutorials.
@edward-vonschondorf-dev
@edward-vonschondorf-dev Ай бұрын
Great video Cosden! It's definitely something I've been looking into lately cause I don't like long complex components that I have to edit/create. I was just curious about something though, i noticed in your imports you have an @ symbol at the beginning and was wondering how that was setup and if there is an advantage to it? Thanks!
@cosdensolutions
@cosdensolutions Ай бұрын
it's import aliases, the advantage is it makes things cleaner, and if you move things you don't have to always have everything be rewritten
@sathirabandara7981
@sathirabandara7981 Ай бұрын
great video. its very useful. 🤩
@bruce_k3lly
@bruce_k3lly Ай бұрын
Thank you for this amazing video it's really helpful and it has increased my productivity, but can I use utils folder, as you said and just add reusable function for similar work ?
@JericAdriano-yo9pv
@JericAdriano-yo9pv Ай бұрын
How about modals or dialogs that are used in one page? Do we handle them all in the parent component?
@SahilPatel-kh2rt
@SahilPatel-kh2rt 23 күн бұрын
Hey, which vs code theme you are using.? Excited to use it for my self also.
@64revolt
@64revolt 14 күн бұрын
What do you think of atomic design and styled components? Only got to the page layout so far, but that seems like a perfect case for that, no?
@QueeeeenZ
@QueeeeenZ 27 күн бұрын
I think you can use Nuxt and all the layout, structure will be already configured for you out of the box.
@2positive1
@2positive1 7 күн бұрын
I would move static data array upper, from the App component. It’s static, no need to recreate it on every re-render.
@kit3x663
@kit3x663 29 күн бұрын
I have one question. Why you didn't use React.FC or forwardRef in any of your videos. Is it usseles to use?
@user-dd7kw3ym5i
@user-dd7kw3ym5i 29 күн бұрын
should I still separate the fetching hook if only one component uses it?
@techaddictdude
@techaddictdude Ай бұрын
Shouldn't the PageLayout.tsx be located in the pages folder, while the 'Profile' file should be in the in components?
@harithsenevi4
@harithsenevi4 28 күн бұрын
Can't we just use the useFetchProfile hook inside the ProfileData component itself instead of passing profileData as props from ProfilePage component? Is it a bad practice? What complications could have with that approach?
@ianfrye8988
@ianfrye8988 Ай бұрын
Great video. Only question I have: why not move the useFetchProfile inside the ProfileData page instead of passing it as a prop?
@ExileEditing
@ExileEditing Ай бұрын
I struggle with choosing between fetching on the page and passing down or fetching in the components as well. I think it makes sense for both, but it is better if you separate concerns and fetch from the page. This way, your component only cares about rendering and doesn't deal with how it gets the data. It makes those components simpler as well and probably easier to test
@cosdensolutions
@cosdensolutions Ай бұрын
because ProfileData is only responsible for rendering, not fetching. Also, if you want to show profileData but with different filters or page sizes, adding that inside will be a mess. The way I did it, the parent decides that and just gives it to ProfileData to take over. It's simpler
@ianfrye8988
@ianfrye8988 Ай бұрын
@@cosdensolutions Thanks for clarifying!
@sontranvan5348
@sontranvan5348 29 күн бұрын
​@@cosdensolutions but in case I need to use the data of filters or page sizes from ProfileData to refresh profiledata, should I use a callback to left it to ProfilePage or move fetching into ProfileData component?
@FiguringOutWhatIsLife
@FiguringOutWhatIsLife Ай бұрын
I mean isn't the children example you gave in the first one just what we do in App.jsx though?
@isaacjames8735
@isaacjames8735 22 күн бұрын
Make a video about Social Login system in react please
@mashab9129
@mashab9129 16 күн бұрын
why not having ProfileData component call the useFetchProfile ?
@lyrical6852
@lyrical6852 Ай бұрын
Honest question, are you doing this in the real world app or in your work?
@Divyv520
@Divyv520 Ай бұрын
Hey Man , really nice video ! I was wondering if I could help you with Viral Content ideas in your niche , Script , editing , thumbnail , SEO , Growth and analysis , Leads and appointments for your business , etc in all to you ! Pls let me know what do you think ?
@viophile
@viophile Ай бұрын
What is your view on default exports? In my opinion they should only be used in libraries, not in any other code.
@mahendrasinh_9106
@mahendrasinh_9106 Ай бұрын
if you export as a default then you can import it at any name // Exporting a component with export default const MyComponent = () => { // Component implementation }; export default MyComponent; import MyComponent from './MyComponent'; without export default // Exporting a component with named export export const MyComponent = () => { // Component implementation }; // Importing the component import { MyComponent } from './MyComponent'; you need to call with same name
@PaulSebastianM
@PaulSebastianM Ай бұрын
Default exports should be banned. They are not adhesive to strong typing and make tree shaking impossible especially when mixed with named export.
@delightful209
@delightful209 Ай бұрын
is it me or is the audio levels on this video really low. i have my headphones at 50 % and its quite low compared to other videos
@keklamo1485
@keklamo1485 Ай бұрын
anyone know what allows him to do rjsfc and have the react component with function keyword? i just have rafc and its the arrow funciton i hate it
@cosdensolutions
@cosdensolutions Ай бұрын
check out my vscode setup video
@nicus1504
@nicus1504 Ай бұрын
why would you use export default function instead of export const?
@keklamo1485
@keklamo1485 26 күн бұрын
@@nicus1504 i just like using function better its personal preference
@RoomCorner_
@RoomCorner_ Ай бұрын
Sir i'm interest of React Project but my english isn't very well. Is there subtitle like in KZbin?
@cosdensolutions
@cosdensolutions Ай бұрын
yes there is!
@SingleSeeker
@SingleSeeker Ай бұрын
in a real project , a loading , error is also needed.
@programmerjowo
@programmerjowo Ай бұрын
How to handle authentication on the API
@FalioV
@FalioV Ай бұрын
Why would you use this Layout component on every page like this ? Just pass it to the index route and thats it. Overall I see this is "basic 101" and way far from Sr. react code. And I personally think this is not the best way to describe "custom hooks" as it should be. This profile code belongs to the Service layer. Don't get me wrong, I'm not here to argue, just have some questions over all. :)
@Edgars82
@Edgars82 Ай бұрын
export const router = createBrowserRouter([ { path: '/', element: ( ), errorElement: , children: [ { index: true, element: , }, { path: 'search', element: (... this way all childrens will have layout and no need to import it as wrapper inside page components
@-mahmoudadel2628
@-mahmoudadel2628 Ай бұрын
يمزاجك يا كوزدين
@shakapaker
@shakapaker Ай бұрын
props with children makes children optional, for layout it needs to be required
@CyberSurgeon
@CyberSurgeon Ай бұрын
in your video description ,the project react lik is give me 500 web code .
@TheOnlyJura
@TheOnlyJura Ай бұрын
Lol react andies
@NikulPipariya-hg5mb
@NikulPipariya-hg5mb Ай бұрын
Increase your voice please... Its so low.... Thanks for zooming screen
@tjdgmlchl6305
@tjdgmlchl6305 Ай бұрын
nah I like it because he’s not yelling or doing a “youtuber voice”
@alaskandonut
@alaskandonut Ай бұрын
I’m not just being contrarian. His level are fine.
@adeemmmm
@adeemmmm Ай бұрын
His volume level is good,try to check your speaker
@dr_jacko
@dr_jacko Ай бұрын
If only there was a way to increase the volume of a video??!?
@Pilosofia
@Pilosofia 29 күн бұрын
throw your speakers in the trash and get new ones.
You Are Using useEffect Wrong
14:40
Cosden Solutions
Рет қаралды 30 М.
Learn React Error Boundaries In 7 Minutes
7:07
Web Dev Simplified
Рет қаралды 104 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 6 МЛН
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,1 МЛН
3 Underrated LinkedIn Hacks for Sales and BD
5:21
Web3 Sales Gym
Рет қаралды 9
Python Conditionals and Denzel Washington??
9:56
Hasan Explains
Рет қаралды 9
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 105 М.
40  Activity Ownership Zero To Mastery Academy 1920x1080 510K
4:59
Дмитрий Машарыгин
Рет қаралды 14
Every React 19 Feature Explained in 8 Minutes
7:35
Code Bootcamp
Рет қаралды 105 М.
Are we going back to PHP with fullstack JavaScript?
9:57
Maximilian Schwarzmüller
Рет қаралды 114 М.
Senior Typescript Features You don't Know About - clean-code
13:33
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 450 М.
All 29 Next.js Mistakes Beginners Make
1:45:10
ByteGrad
Рет қаралды 52 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 6 МЛН