Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
127 stars 6 forks source link

feature like getServerSideProps #21

Closed amir1376 closed 4 months ago

amir1376 commented 4 months ago

Hello, first of all thanks for your work

I want to know is there anything like nextjs's getServerSideProps in this library?

I want to fetch a json from remote (and also transform it) in build time and pass it into client for SSG so clients don't have to fetch that data everytime

Daydreamer-riri commented 4 months ago

Of course there is, it's briefly mentioned in the documentation, just use the loader from react-router.

There's also an example here: https://github.com/Daydreamer-riri/vite-react-ssg/blob/main/examples%2Fwith-loader%2Fsrc%2Fpages%2F%5Bdocs%5D.tsx

amir1376 commented 4 months ago

Ah. I didn't see it at first place. Thanks

Daydreamer-riri commented 4 months ago

Thank you for your use. If you have other questions, please let me know and I will reply as soon as possible.

In addition, the current loader will still be executed when the client route jumps. I will implement the Loader API that runs only when the build is in the next minor release.

Daydreamer-riri commented 4 months ago

Hi @amir1376 , as of 0.7.0, the loader will only run on the server.

See: https://github.com/Daydreamer-riri/vite-react-ssg/tree/v0.7.0?tab=readme-ov-file#data-fetch