Skip to content

Commit

Permalink
Fix: Should not warn if store is undefined in getter
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Dec 21, 2023
1 parent 69052ba commit f89840c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/jotai-x/src/createAtomStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,17 @@ export const createAtomStore = <
const setAtoms = {} as SetRecord<MyWritableStoreAtoms>;
const useAtoms = {} as UseRecord<MyWritableStoreAtoms>;

const useStore = (optionsOrScope: UseAtomOptionsOrScope = {}) => {
const useStore = (
optionsOrScope: UseAtomOptionsOrScope = {},
warnIfUndefined = true
) => {
const { scope, store } = convertScopeShorthand(optionsOrScope);
const contextStore = useAtomStore(name, scope);
const contextStore = useAtomStore(name, scope, warnIfUndefined);
return store ?? contextStore;
};

const useAtomValueWithStore: GetAtomFn = (atomConfig, optionsOrScope) => {
const store = useStore(optionsOrScope);
const store = useStore(optionsOrScope, false);
const { delay = delayRoot } = convertScopeShorthand(optionsOrScope);
return useAtomValue(atomConfig, { store, delay });
};
Expand Down

0 comments on commit f89840c

Please sign in to comment.