Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use Provider component imported from jotai #11

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading