ory / kratos-selfservice-ui-react-nextjs

A full reference implementation for designing your own login, registration, recovery, verification, ... pages using Ory Kratos' APIs.
https://www.ory.sh/
Apache License 2.0
135 stars 57 forks source link

Should the session be fetched on each rerender on index page? #26

Closed spietras closed 1 year ago

spietras commented 2 years ago

If I understand correctly, useEffect without any dependencies will be fired on each rerender. If that's the case then we would do unnecessary calls to Kratos, because useEffect will be fired again after we call setSession the first time.

https://github.com/ory/kratos-selfservice-ui-react-nextjs/blob/b3d26868f8eea281480b1ec5053ecab658ca5c19/pages/index.tsx#L19-L44

Should we add an empty array [] as useEffect dependency so it fires only once? Or maybe there is some different reasoning as to why there are no dependencies in this useEffect?

aeneasr commented 2 years ago

Yes, that makes sense to me!