jotaijs / jotai-scope

MIT License
55 stars 4 forks source link

Is useHydrateAtoms only available when using SSR? #37

Closed ampcpmgp closed 2 months ago

ampcpmgp commented 2 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 2 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 2 months ago

You can use useHydrateAtoms without SSR.

ampcpmgp commented 2 months ago

有難うございます!