jotaijs / jotai-scope

MIT License
60 stars 4 forks source link

Is useHydrateAtoms only available when using SSR? #37

Closed ampcpmgp closed 4 months ago

ampcpmgp commented 4 months ago

I found useHydrateAtoms in the documentation, but since it is in the SSR section, I wasn't sure if it was available when not using SSR.

https://jotai.org/docs/utilities/ssr

Is there any problem to use it when non-SSR?

ampcpmgp commented 4 months ago

The following code is assumed in non-SSR.

// atoms
const eventAtom = atom<Event | null>(null)

// How to use provider
functtion Events () {
  return (
    <>
      {events.map(item => (
        // default value is null
        <ScopeProvider atoms={[eventAtom]}>
          // set initial value
          <?? initialuValue={item}>
            <Event />
          </??>
        </ScopeProvider>
      )}
    </>
  )
}

// How to use scoped atom
function Event () {
  const [event] = useAtom(eventAtom)
  return (
    <div>
      // I want to remove optional and type-safe, if possible.
      <span>title: {event?.name}</span>
    </div>
  )
}
dai-shi commented 4 months ago

You can use useHydrateAtoms without SSR.

ampcpmgp commented 4 months ago

有難うございます!