Path To A Clean(er) React Architecture - API Layer & Data Transformations

Sdílet
Vložit
  • čas přidán 9. 05. 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...

Komentáře • 22

  • @panchcw
    @panchcw Před 26 dny

    Really helpfull On CZcams there are a lot of tutorials about basic stuff but these are the real gems.keep it up

  • @sayedaliaqamousavi9064
    @sayedaliaqamousavi9064 Před 21 dnem +1

    I was looking for such kind of videos. Thanks, alot.

  • @bryant3060
    @bryant3060 Před 24 dny

    I am having the exact same problems currently in my app! Thank you for this series!

  • @gauravrawat7175
    @gauravrawat7175 Před 29 dny

    keep these videos coming, really helpful. lots of love.

  • @user-yz2mv8kn4x
    @user-yz2mv8kn4x Před 29 dny +1

    found these refactoring videos extremely helpful and insightful. thank you so much. 🙏

    • @profydev
      @profydev  Před 29 dny +1

      Thanks a lot for the feedback. More videos to come :)

  • @abbaskareem5281
    @abbaskareem5281 Před 28 dny +5

    I hope you make a video on pagination with limit&offset and filters (query params)

    • @BRP-Moto-Tips
      @BRP-Moto-Tips Před 24 dny

      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

  • @milad8436
    @milad8436 Před 19 dny

    Very helpful. Thank you

  • @bonedfps
    @bonedfps Před 29 dny +1

    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?

    • @profydev
      @profydev  Před 29 dny

      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

    • @bonedfps
      @bonedfps Před 26 dny +1

      @@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.

  • @gustavoeklund
    @gustavoeklund Před 26 dny

    I just came from CZcams home and these videos caused me a disease: I die if you stop posting them

  • @gamingxsvssdeva4245
    @gamingxsvssdeva4245 Před 12 dny

    can you attach github repo for this project

  • @realTalhaMeer
    @realTalhaMeer Před 25 dny

    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

    • @profydev
      @profydev  Před 24 dny

      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

    • @realTalhaMeer
      @realTalhaMeer Před 24 dny

      make some clarity. it would be better if you address this part in the upcoming videos.

  • @NoName-bu5cj
    @NoName-bu5cj Před 25 dny

    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()
    ```

    • @profydev
      @profydev  Před 25 dny

      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 😂