Skip to content
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

SSR Example #2

Closed
popuguytheparrot opened this issue Nov 2, 2021 · 4 comments
Closed

SSR Example #2

popuguytheparrot opened this issue Nov 2, 2021 · 4 comments

Comments

@popuguytheparrot
Copy link

It would be very nice to see an example for SSR with for example nextjs

@ai
Copy link
Member

ai commented Nov 2, 2021

@popuguytheparrot
Copy link
Author

in this example let locale, i18n will shared for all users on each request.

How can i hydrate locales to store and cleanup on server?

So, in Next.js i need serialised data to gssp props

import { locale } from 'nanostores'

let locale, i18n

if (isServer) {
  locale = atom(db.getUser(userId).locale || parseHttpLocaleHeader())
  i18n = createI18n(locale, {
    async get (code) {
      return JSON.parse(await readFile(`public/translations/${code}.json`))
    }
  })
} else {
  
}

export { locale, i18n }

@ai
Copy link
Member

ai commented Nov 2, 2021

in this example let locale, i18n will shared for all users on each request.

You need to use your framework’s APIs for this. You can avoid using a separated file for every store and initialize all stores together in some functions like buildContext(). Or you can export store builder from every file.

So, in Next.js i need serialised data to gssp props

Sorry, I do not use Next.js to suggest exact solution.

If you need some specific API, ask for it.

@ai
Copy link
Member

ai commented Nov 2, 2021

I am closing this issue. We have a similar “What is the best SSR integration” discussion in main Nano Stores repository.

But without an API suggestions from Next.js users I can’t help.

@ai ai closed this as completed Nov 2, 2021
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

No branches or pull requests

2 participants