Hacker News new | ask | show | jobs
by obilgic 3524 days ago
Don't fetch within a component. Write a helper function: getUser(). It should decide which method to use to retrieve data.
1 comments

How would it decide? What does the server-side version do since it won't have access to the req or res objects at this level of the code? If the /api/user/:id route is restricted based on the cookies that get sent, how/where do you validate that the user is allowed to get data from that route when rendering server-side?
That would be the responsibility of the route code, not the code doing the fetch().
Why would the route code need to know what data a deeply nested component needs? Making that the responsibility of the route code entirely defeats the purpose of an isomorphic/universal React application.