Пікірлер
@letmein985
@letmein985 Күн бұрын
aha, although it works, Dan Abramov himself probably realises, how ugly that is. New react won't need that at all :D Ban use effect entirely
@mrlectus
@mrlectus 3 күн бұрын
Last issue is not using typescript
@PetersExcapades
@PetersExcapades 3 күн бұрын
im confused about the usage of !!, i understand it does a double negation and converts to boolen, but why concert to boolean if the value is falsy anyway?
@Igstefano
@Igstefano 3 күн бұрын
More than that, couldn't he just have used Map.has() instead of double negating Map.get()?
@LongPham-lr4eh
@LongPham-lr4eh 4 күн бұрын
❤ Thank you, I learned a lot
@MM-pw4ft
@MM-pw4ft 4 күн бұрын
100% do more refactoring videos, these are rare and idk if it's specifically your unique idea to do this, but this is actually gold content
@franciscoizaguirre9069
@franciscoizaguirre9069 5 күн бұрын
I wish I saw this YEARS ago, that was awesome and insightful
@MatviiRubets
@MatviiRubets 5 күн бұрын
bro don't be so serious when you record a vid :D you look like ur about to get killed
@vuxuanhuy9079
@vuxuanhuy9079 5 күн бұрын
Keep going 🎉
@jeremykothe2847
@jeremykothe2847 5 күн бұрын
WTF is with the bot comments?
@Hacking-Kitten
@Hacking-Kitten 6 күн бұрын
bitflag, where?
@kalilbarry3773
@kalilbarry3773 6 күн бұрын
From reading the comments, it seems like Clean Architecture is not well received in the React community. Coming from Flutter, this is a very standard approach when building medium-large app. I'm currently learning NextJS and my first thought was, how can I apply Clean Architecture to it... But to be honest, it is simpler in Dart to manage DTOs and other stuff because I'm more used to classes than JS objects. But it is probably a matter of time to get used to it and find a way to translate my Dart architecture to Typescript.
@profydev
@profydev 6 күн бұрын
I’m also not sure why there’s so much push back. On Reddit the comments were much more diverse and surprisingly supportive. Most of the projects I’ve seen didn’t have a real architecture. at least when it comes to separating business logic, data access, and UI. What I’ve seen is more often than not mix and match. One thing that’s different with react is the functional code. So you can’t really work with classes and such in an OOP way. But it’s possible to adapt e.g. clean architecture to work with react to some extend. Anyway, thanks for your feedback.
@kalilbarry3773
@kalilbarry3773 6 күн бұрын
@@profydev the last part of your reply! This was the most disorienting thing when I started learning React/Next. Almost everything is an isolate function and I’m not used to that… I always call function through class interfaces to abstract away stuff, like recommended in DDD. But actually, I’m not sure on how to implement that in TS. Maybe a video on that?
@gamingxsvssdeva4245
@gamingxsvssdeva4245 6 күн бұрын
can you attach github repo for this project
@DomskiPlays
@DomskiPlays 6 күн бұрын
Wow this video was actually amazing, that's wild!
@francolinares7312
@francolinares7312 7 күн бұрын
Great video! Keep making them
@MrBumbo90
@MrBumbo90 7 күн бұрын
can't wait for the react query video!
@joshuakawamata5406
@joshuakawamata5406 7 күн бұрын
I thin kyou talk too fast makes it harder to comprehend what youre saying. Otherwise great tips
@yubtubtime
@yubtubtime 7 күн бұрын
Finally, someone who understands architecture on the front-end 🥲 There are way too many small and mid-sized firms whose front-end is wholly coupled to their data architecture, and managing adapters throughout their applications consumes 99% of their front-end efforts. You try your best to implement clean architecture, but managers and directors simply aren't used to seeing it on the front-end, so they just can't wrap their heads around the idea of investing any time at all into what seems like unnecessary "reorganization" to them. Oh, how they love to reorg a team though, but that's another rap. I'll tell you why people think this is weird: sexism. The front-end is seen as "girly". As a woman whose worked both in AI and as a web developer, the latter is so, so, so much harder...but no one will believe me because the front-end is "basically just design". I've seen statistics corroborating that female developers are disproportionately given front-end work because it's seen as "light", but I've lost the source. It's also important to note that this is a spectrum that affects everyone. Tech does not tolerate, much less reward, any kind of femme behavior, from women or men, regardless of value even to the bottom line. What most don't realize about a highly customized and sophisticated front-end is that it isn't "basically just design", rather it's closer to engineering a *design tool* like Photoshop. My academic background is in mathematics and theoretical computer science, and I was drawn to the front-end because it can be very math heavy. Again, remember that most pre-digital "computers" were women, and even Einstein's personal calculations were often carried out by his wife. All of this careful and meticulous calculation is still seen as trivial and "light" though, despite being necessary machinery. Despite Einstein himself saying this work was necessary for him to complete his theories, folks online will still argue with you otherwise that he could have produced the same results with anyone. Women in science and computing are treated as *fungible* resources. As a result of this perceived fungibility, managers and directors truly *can't imagine* spending the time to keep these workers' workspaces in order. Since we're primarily handed front-end work as femmes, the idea of giving our workspace a clean architecture is dismissed as a waste of time. Women (and femmes generally) have always had to work in filth and slop. Of course, this perception hurts all engineers regardless of gender, which is just one example of how Patriarchy is damaging to everyone and everything. This even includes productivity and ultimately profitability.
@kakun7238
@kakun7238 8 күн бұрын
thank you sir a suggestion tho could you please zoom in
@wshewm
@wshewm 8 күн бұрын
A lot of people in the comments are saying DTO doesn't make sense on frontend. I think the strengths become more apparent when you bring full-stack in frameworks like Next.js. You can consume data from multiple different services and bring it together in a nice clean package to send to the frontend using something like tRPC. Also, this is useful for data security. Since you are explicitly defining what gets sent to the frontend, you are protecting sensitive information from making it through the transfer layer
@wshewm
@wshewm 8 күн бұрын
I use tRPC which seems to accomplish a lot of this automatically. What are your thoughts on tRPC?
@profydev
@profydev 5 күн бұрын
Haven’t tried it yet but heard a lot of good things. Could make sense to create a backend-for-frontend wrapper around the original REST API. Although that would only delegate the problem to another place 🤷
@StingSting844
@StingSting844 8 күн бұрын
I dont agree that this is a good pattern for the frontend. This is a nightmare for debugging. And when multiple components expect the same object from the server for different rendering ways it will break differently in different places. We dont want that. We can solve the main issue here by simply by grouping the marshalling functions near the consumers in something like a util file specific to that component. There is no more nested lookups and other issues. This will not complicate the codebase since there is no extra thing to remember and typescript will help us with the structural issues anyway
@Stragunafen
@Stragunafen 8 күн бұрын
Loved this kind of video!
@user-pq8zg6rx8c
@user-pq8zg6rx8c 8 күн бұрын
You could’ve simply used Zod. Using a schema inside your API layer makes possible doing “transform” after parsing data. This way you write all data transformations at once
@user-pq8zg6rx8c
@user-pq8zg6rx8c 8 күн бұрын
You could’ve simply used Zod. Using a schema inside your API layer makes possible doing “transform” after parsing data. This way you write all data transformations at once
@profydev
@profydev 8 күн бұрын
Good point, thanks for bringing it up. Could make a good future video
@TheRajDMC
@TheRajDMC 8 күн бұрын
I think this makes sense to me since I had a situation where I used similar approach. We had a frontend app that received a huge json response with 100s of fields to render a product offer. So instead of directly using its field throughout the app, I created a transformation file which maps it according to what makes sense in the app. Advantages: - If there is a change in backend api, I just need to update the transformation file in most cases - I can rename things/restructure the json to what makes sense to me and the frontend app instead of relying on backend developers naming/structuring We event had a huge change in backend api which caused the entire json response to change but because I had used the transformation function, it saved me hours of work since I had to mostly change that file to integrate with the updated api.
@toomanyarguments
@toomanyarguments 8 күн бұрын
nobody use dto in Frontend codebase.
@svenkang7356
@svenkang7356 8 күн бұрын
Cleaner architecture by what standards? This is applying wrong solutions to problems that do not exist. Instead of trying to force these patterns into your codebase, understand what kind of real problems these patterns are solving so you can apply them correctly.
@profydev
@profydev 8 күн бұрын
Of course you shouldn't force any patterns in a codebase where they don't make sense. In this case it introduces a separation of UI code and server which makes sense in large and complex applications. But there's no need to use these patterns when the API responses match the domain models, when you build a small project or write throwaway code for a MVP. As I said, no silver bullets :)
@AnotherSmartMonkey
@AnotherSmartMonkey 8 күн бұрын
If you have a list of Users for a getAllUsers method That would meen that dtoToUsers will do a for loop over each user object to have the good format right ? It could slow down your application if you have a lot of users in your json server response
@illegalsmirf
@illegalsmirf 8 күн бұрын
Another weird-looking JS dev. Is it obligatory for senior JS devs to have a mustache and weird hairdo?
@mayanksharma6927
@mayanksharma6927 8 күн бұрын
I'm still not sold on this one. DTOs are not a pattern for react, they're a pattern for server code within OOP. To me all of this seems really unnecessary when you could just define a custom user type and only use the values you really need from the server. These values are now directly linked to the server values and can be modified at any point of time, without affecting the rest of the application. You could have a simple user object that doesn't follow the API structure but links to different values in the API. like, userId: apiResponse.id, followers: apiResponse.relationships.followers. There's no need to complicate the code.
@profydev
@profydev 8 күн бұрын
You mean that we don't use everything the server returns like "user.attributes.someUselessField" but apart from that define TypeScript interfaces that follow the server data? Like "user.attributes.name" or "user.relationships.followerIds"? You can do that for sure. And for many apps this will be enough. Actually that's what the main repository at my current job does. But for one it's pretty ugly imo. That's not necessarily a reason to introduce a lot of code overhead of course. But exposing these data structures to even the most nested component in the tree means you have coupled the whole frontend to the server API. Which in many cases is ok. But if you think in terms of long running and very complex projects there's the risk that there are significant changes in the API or other data sources. And then this tight coupling between UI and server becomes a problem. In the end that's the reason why there are these classic patterns in software development: isolate parts of the code so they become more independent from each other. More resilience and more maintainability over the long run. With the downside of more complexity and more code of course. It's always a tradeoff
@bryant3060
@bryant3060 8 күн бұрын
Thank you Profy! I am crossing each one of these hurdles just as you release a new video
@profydev
@profydev 8 күн бұрын
Thanks for the feedback :)
@internetexplorer7880
@internetexplorer7880 9 күн бұрын
Kinda stupid. What if it's the other way around and user data now has to be under the attributes property. Goes back to square 1 where you need to change 90% of the frontend code
@profydev
@profydev 8 күн бұрын
It's about thinking in terms of domain entities. A user has a name so the model should be user.name. There's no reason to have user.attributes.name because that doesn't reflect the domain model. There's a risk though that the API decides to use a different model for data transfer as this doesn't have to strictly follow the domain model.
@MichaelKire
@MichaelKire 8 күн бұрын
In frameworks like nextjs it's also about what gets sent out to the client/browser. Let's say you get some data from an endpoint where you only need x amount of data from it, there's no reason to spend bandwidth as well on sending it to the client to then just never use it. Not to mention potential extra cpu cycles using on processing the extra data which is not used in the end. It might also be that you want to do some extra processing before sending it off to the client.
@ekekw930
@ekekw930 9 күн бұрын
should there not be a service layer that handles business logic in between the component and Api layer? Component -> service -> api?
@davidecarvalho7077
@davidecarvalho7077 9 күн бұрын
React encourages you to have self contained components, so UI and behavior lives together "But what should we do if the component gets too big" maybe it's time to separate it into smaller components then
@bryant3060
@bryant3060 8 күн бұрын
I came across the same thought/problem. My solution was to refactor "services" into hooks with files near the components. It keeps the ui components simple and makes it easier to test
@profydev
@profydev 8 күн бұрын
I'll introduce "use cases" in a future video. It's a concept from Clean Architecture and encapsulates business logic. But basically it's what you mean if I understand correctly. And basically they are also just hooks as @bryant3060 said in another comment
@profydev
@profydev 8 күн бұрын
That's right. It's still helpful to think in terms of UI logic, business logic, data access and so forth. From my experience few React developers have this in mind and that results in components where everything's mixed together.
@edhahaz
@edhahaz 9 күн бұрын
React coupled structure with javascript, and it was great, then came tailwind and coupled styling with react, and it was great, ... came and coupled APIs with react tailwind... and it was fucking great.
@tusharghildiyal6814
@tusharghildiyal6814 9 күн бұрын
this is really some professional coding advice. helps a lot in real world applications unlike the most beginner friendly tutorials on youtube
@alvin_lal
@alvin_lal 9 күн бұрын
Very helpful tutorial, can u share names of any good tools that automates the dto type generation , if u have used any before , thanks
@profydev
@profydev 9 күн бұрын
Thanks. I wrote a blog post a while ago about code generation based on OpenAPI specs: profy.dev/article/react-openapi-typescript
@Ivan-wm6gm
@Ivan-wm6gm 9 күн бұрын
quite weird using dto in frontend
@profydev
@profydev 8 күн бұрын
Why? In the end, that's what the server returns in this case. Here it helps isolating UI from the server which makes sense in large and complex applications. No need to use this in small projects of course.
@Ivan-wm6gm
@Ivan-wm6gm 8 күн бұрын
@@profydev its just completely weird using clean architecture in frontend. CA is usually applied in microservice or modular monolith backend service. I've seen big projects both frontend and backend but I've never seen anyone using CA in frontend
@devyb-cc
@devyb-cc 8 күн бұрын
I used it a lot with mobile development.
@profydev
@profydev 8 күн бұрын
@@Ivan-wm6gm I’m wondering why it’s so weird in your opinion. What’s the core difference that makes CA useful on the backend but not the frontend?
@kirarevcrow
@kirarevcrow 7 күн бұрын
Let me tell you why it's weird, because in KZbin we rarely see deep dive into real life examples about clean architecture Some patterns that are used on the backend can be used on the front, no issue with that at all
@kyrregjerstad
@kyrregjerstad 9 күн бұрын
I really enjoy these videos! As a relatively new React developer who values a clean codebase, I find them incredibly helpful. I have a question about crafting a clean API layer i hope your could answer. Imagine an API returns rate-limiting info in the response headers. When the rate limit reaches a certain threshold, we want to inform the user before they hit the limit. The components consuming the API response do not care about the rate limit info. What would be a good pattern to implement this as a “middleware” between the API layer and component consumers, ensuring the components remain unaware of the rate-limiting logic? When the threshold is reached, we want to trigger a side effect on the client from the server to display the notification.
@greyshopleskin2315
@greyshopleskin2315 9 күн бұрын
I’m a backend guy so take this with a grain of salt. I guess if you’re using global state (redux, zustand, etc) you could store the rate limit info on global state and have a component to notify the user that reads it. Doing it this way would cause unnecessary rerenders of that component but that can be fixed
@profydev
@profydev 8 күн бұрын
If I understand correctly you have API responses that contain some meta information about rate limiting and you want to show some kind of global notification that's indepenent of the component fetching the data. Just from the top of my head: You might define a TypeScript interface for rate limited meta data. The data source (here the fetch function) could extend this interface e.g. return `{ user: ..., rateLimit: ... }`. You could process this kind of values in a `function processRateLimit<T extends RateLimit>({ rateLimit }: T) {...}`. This function then e.g. dispatches a Redux action or updates a state in a context depending on what state management approach you use. I'll introduce a concept called "use case" in a future video which could be useful to handle the processing of this meta info in between the API layer and the component. So basically the component doesn't need to be aware of the rate limiting. It's all isolated in the "use case" which is basically a glorified hook :)
@SpikeYOLO994
@SpikeYOLO994 9 күн бұрын
One question , the thing where you replace the for loop for counting elements that have the status open with a filtered array ( arr.filter().length ) just to have it just "pretty" impact the memory usage ? U don't just iterate thought the the array that you have , u create a new array so , allocating more memory .Maybe a middle ground can be a reducer :D
@SpikeYOLO994
@SpikeYOLO994 9 күн бұрын
Nvm , I didn't get to the part where you mentioned about memory :D , great job XD
@profydev
@profydev 8 күн бұрын
Haha thanks
@fabrzy3784
@fabrzy3784 9 күн бұрын
Amazing video ! May I ask when is it appropriate to use a map vs an array?
@mateito191
@mateito191 10 күн бұрын
I feel bad I just don’t understand
@miceyjuice9175
@miceyjuice9175 10 күн бұрын
I love these kinds of videos! Great stuff!
@user-do7ky1ez6r
@user-do7ky1ez6r 10 күн бұрын
You hooked me as your subscriber. congratulations 🎉
@Gelu84
@Gelu84 10 күн бұрын
Great video! I would love to see more of these
@NoopDawg
@NoopDawg 10 күн бұрын
This is wonderful, this kind of content is very helpful
@yt-sh
@yt-sh 10 күн бұрын
I subbed, hoping to see more refactoring videos!!
@a7mdbest15
@a7mdbest15 10 күн бұрын
thank you very much for the video
@user-zo2ky4mz7d
@user-zo2ky4mz7d 10 күн бұрын
This is awesome. The frontend community needs more resources like this. Subscribed +1 Thank you.
@profydev
@profydev 10 күн бұрын
Thanks for the feedback. I feel the same way. This stuff is very common on the backend but not on the frontend for some reason.
@nested9301
@nested9301 11 күн бұрын
Mmmore of. This please
@yoz0__
@yoz0__ 11 күн бұрын
You can just use Set instead of Map, cause you only set value for the key to true.