Skip to content

Commit

Permalink
Merge pull request #11 from udecode/fix/jotai-atom-provider-interferi…
Browse files Browse the repository at this point in the history
…ng-with-vanilla-atoms

Do not use Provider component imported from jotai
  • Loading branch information
Ziad Beyens authored Feb 28, 2024
2 parents 5b179fe + bfa81b1 commit 5fb32bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-pets-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'jotai-x': patch
---

Do not render jotai's Provider component as part of jotai-x's provider. Jotai's Provider is unnecessary and interferes with vanilla jotai atoms.
6 changes: 0 additions & 6 deletions packages/jotai-x/src/atomProvider.ts

This file was deleted.

24 changes: 11 additions & 13 deletions packages/jotai-x/src/createAtomProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { createStore } from 'jotai/vanilla';

import { AtomProvider, AtomProviderProps } from './atomProvider';
import { JotaiStore, SimpleWritableAtomRecord } from './createAtomStore';
import { useHydrateStore, useSyncStore } from './useHydrateStore';

Expand Down Expand Up @@ -43,12 +42,13 @@ export const useAtomStore = (
return store;
};

export type ProviderProps<T extends object> = AtomProviderProps &
Partial<T> & {
scope?: string;
initialValues?: Partial<T>;
resetKey?: any;
};
export type ProviderProps<T extends object> = Partial<T> & {
store?: JotaiStore;
scope?: string;
initialValues?: Partial<T>;
resetKey?: any;
children: React.ReactNode;
};

export const HydrateAtoms = <T extends object>({
initialValues,
Expand Down Expand Up @@ -116,13 +116,11 @@ export const createAtomProvider = <T extends object, N extends string = ''>(

return (
<AtomStoreContext.Provider value={storeContext}>
<AtomProvider store={storeState}>
<HydrateAtoms store={storeState} atoms={atoms} {...(props as any)}>
{!!Effect && <Effect />}
<HydrateAtoms store={storeState} atoms={atoms} {...(props as any)}>
{!!Effect && <Effect />}

{children}
</HydrateAtoms>
</AtomProvider>
{children}
</HydrateAtoms>
</AtomStoreContext.Provider>
);
};
Expand Down
1 change: 0 additions & 1 deletion packages/jotai-x/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file Automatically generated by barrelsby.
*/

export * from './atomProvider';
export * from './atomWithFn';
export * from './createAtomProvider';
export * from './createAtomStore';
Expand Down

0 comments on commit 5fb32bf

Please sign in to comment.