-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: getInitialProps/getClientSideProps #364
Comments
The problem is that |
there's for example: export const ssr: SSROptions = {
props: async ({ params }) => {
const res = await fetch(`http://example.com`)
if (res.status !== 200) {
console.log(await res.text())
return {}
}
const json = await res.json()
return json as WalletData
},
paths: () => {
return []
}
} |
what if we allow to access the export default function Page() {
const isLogined = useDeno(req => {
return req.headers.get('Auth') === 'XXX'
}, { revalidate: true })
return (
<p>isLogined: {isLogined}</p>
)
} with export const ssr: SSROptions = {
props: req => {
return {
$revalidate: true,
username: req.params.username,
logined: req.headers.get('Auth') === 'XXX'
}
}
} |
@ije second options makes more sense since it already exposes request parameters |
The useDeno hook is very clean to use |
We can put params in req |
updated, |
added in beta.18 |
IMHO getInitialProps is very useful but complex to re-implement properly and to bundle properly
What I suggest is
getServerSideProps
, which we already have, combined with a new function namedgetClientSideProps
.This function would generate the props client-side, just like getInitialProps, but without being compatible with the server
getServerSideProps
is calledgetClientSideProps
is calledThis way, no request to the server is made each time the user clicks somewhere, especially if the client already has the props in a cache (e.g. swr)
If
getClientSideProps
is NOT defined, then a request is made andgetServerSideProps
is called server-side (current behaviour)The bundling of those two functions is easier than
getInitialProps
, and their behavior is more understandable and less error-proneThe text was updated successfully, but these errors were encountered: