Skip to content

Conversation

@DarkoKukovec
Copy link
Member

No description provided.


// TODO: Should this be here?
// TODO: Invalidation?
export const withAuth = (Component: React.FC): React.FC => {
Copy link

@isBatak isBatak Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use HOC pattern now when we have hooks.
This could easily be an useAuth hook and the loading state is handled explicitly by the user of the hook. Doing it like this you have much more control of the UI, for example, you can use different skeleton animation on each page depending on the content type. It maybe seems like a lot of repetition, like you have to copy the same chunk of code to every page, but that is not a bad thing because you can do the abstraction elsewhere, like put everything into <PageLoader /> component abstraction that you repeat across the pages.
Here is an example:
https://github.com/vercel/next.js/blob/canary/examples/with-iron-session/pages/profile-sg.js#L5
https://github.com/vercel/next.js/blob/canary/examples/with-iron-session/pages/login.js#L8 - here hook handles redirects

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I found HOCs hard to type when they pass some new props to the wrapped components.

@isBatak
Copy link

isBatak commented May 28, 2021

This is one really old PR... I'll close this PR sorry

@isBatak isBatak closed this May 28, 2021
@isBatak isBatak deleted the feature/logic branch June 20, 2022 15:27
kamdubiel added a commit that referenced this pull request Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants