Path To A Clean(er) React Architecture - API Layer & Data Transformations
HTML-код
- Опубликовано: 9 май 2024
- Step 3 in the architecture cleanup:
Move transformations of API data to a shared API layer. This hides the complexity of the response data structures decoupling API and UI code.
Here’s the blog post including a course waitlist: profy.dev/article/react-archi...
Really helpfull On RUclips there are a lot of tutorials about basic stuff but these are the real gems.keep it up
I am having the exact same problems currently in my app! Thank you for this series!
I was looking for such kind of videos. Thanks, alot.
keep these videos coming, really helpful. lots of love.
I hope you make a video on pagination with limit&offset and filters (query params)
depending on what youre building you might want to extract that logic into a hook, i usually work with dashboards and its great because each table has it own hook instance with different config props and it all falls into place nicely
found these refactoring videos extremely helpful and insightful. thank you so much. 🙏
Thanks a lot for the feedback. More videos to come :)
Very helpful. Thank you
Hello there, I just came across your video on my youtube homepage.
First up: nice video and great sound quality! Tho, I think the separation of concerns, that you are basically talking about, is great, it becomes increasingly harder when working with server components. Moving your data logic to a separate function is the right choice, but error handling is still pain, even if one goes after what you suggest. It still requires either catch callbacks or an error state field to be used, which in turn makes the code unclean again like it was from the get go.
What is your opinion or way of working on that?
That's a good question. I don't have a lot of experience with server components yet. Do you mean in the context of Next.js? Would be awesome if you could send some example code or a GitHub repository
@@profydev Hey, yeah I meant in the context of Next, tho unfortunately the projects im working on are all closed source, so I can't share anything.
What is common tho is to return an object in a server action, that represents the current state, e.g. "error" or "success", with the appropriate response data. In the frontend we'd have to check for that state in ugly ways, which is what I meant with that, in the end, it all becomes unclean again.
I just came from RUclips home and these videos caused me a disease: I die if you stop posting them
can you attach github repo for this project
As per your implementation, you only return the data, that is being used in that component, what if an API is being used in two different components. Please explain or create a video on it.
Thanks
Actually the fetch function returns all the data from the endpoint but simply transforms it to isolate the components from the exact response data structures. Maybe this will become clearer in the next video where we introduce shared domain models
make some clarity. it would be better if you address this part in the upcoming videos.
wouldn't it be better to return a more generic object from api? say you decided you don't want your users to shout. you want them to whisper. you'll have to change the code inside both the component and the api. you could instead return a generic `data` property and inside the component name it whatever you want:
```js
const { data: shouts } = API.getShouts()
```
I think if the underlying entity changes you have to adjust a large chunk of the codebase anyway. But good point about the naming. It’s kind of like Twitter became X and Tweets became Posts, right? I’m wondering how many references to "tweet" are in the X/Twitter codebase 😂