Jotai v2: why not keep/add initialValues API #1788
-
Currently I have to use a workaround, to use the same Provider API. My utility function export function createJotaiStore(pairs: [PrimitiveAtom<any>, any][]): JotaiStore {
const s = createStore()
for (let pair of pairs) {
const [atom, v] = pair
s.set(atom, v)
}
return s
} example code const store = createJotaiStore([
// general
[notistackAtom, { enqueue: enqueueSnackbar, close: closeSnackbar }],
[routerAtom, { push: router.push, pathname: router.pathname, query: router.query }],
[sessionAtom, session],
[isDevAtom, isDev],
[isAdminAtom, isAdmin],
[isGroupOrganizerModeAtom, isGroupOrganizerMode],
// saving
[savedTripAtom, trip],
[savedUiSettingsAtom, settings ?? null],
// trip
[tidAtom, tid],
[tripNameAtom, trip.name],
])
return (
<Provider store={store}>
<TripStepPage />
</Provider>
) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In v2, the recommendation is to use As for API design, we try to avoid providing multiple ways (this applies not only to jotai but also to other state libs in pmndrs). So, creating a util on your end (or in a third-party library) is very expected. |
Beta Was this translation helpful? Give feedback.
In v2, the recommendation is to use
useHydrateAtoms
which is more flexible. Maybe there's room for improvement in the migration guide.As for API design, we try to avoid providing multiple ways (this applies not only to jotai but also to other state libs in pmndrs). So, creating a util on your end (or in a third-party library) is very expected.