From 20b4fd8b73295db3fe8b7659585c388b74404440 Mon Sep 17 00:00:00 2001 From: Daishi Kato Date: Tue, 30 Jan 2024 20:03:20 +0900 Subject: [PATCH] fix(isolation): fix prop types (#15) * fix(isolation): fix prop types * update CHANGELOG --- CHANGELOG.md | 2 ++ examples/01_isolation/src/App.tsx | 8 ++++---- src/createIsolation.tsx | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee18e92..0863125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +### Changed +- fix(isolation): fix prop types #15 ## [0.5.0] - 2024-01-26 ### Changed diff --git a/examples/01_isolation/src/App.tsx b/examples/01_isolation/src/App.tsx index 67b83cb..8fc03e8 100644 --- a/examples/01_isolation/src/App.tsx +++ b/examples/01_isolation/src/App.tsx @@ -17,7 +17,7 @@ const Counter = () => { ); }; -const ScopedCounter = () => { +const MyCounter = () => { const [count, setCount] = useMyAtom(countAtom); return (
@@ -35,12 +35,12 @@ const App = () => {

First Provider

- +

Second Provider

- + - +
); diff --git a/src/createIsolation.tsx b/src/createIsolation.tsx index f3a0024..a4c677c 100644 --- a/src/createIsolation.tsx +++ b/src/createIsolation.tsx @@ -1,6 +1,7 @@ import { createContext, useContext, useRef } from 'react'; import type { ReactNode } from 'react'; import { createStore } from 'jotai/vanilla'; +import type { WritableAtom } from 'jotai/vanilla'; import { useAtom as useAtomOrig, useAtomValue as useAtomValueOrig, @@ -9,25 +10,25 @@ import { import { useHydrateAtoms } from 'jotai/react/utils'; type Store = ReturnType; -type InitialValues = Parameters[0]; +type AnyWritableAtom = WritableAtom; export function createIsolation() { const StoreContext = createContext(null); const Provider = ({ store, - initialValues = [] as unknown as InitialValues, + initialValues = [], children, }: { store?: Store; - initialValues?: InitialValues; + initialValues?: Iterable; children: ReactNode; }) => { const storeRef = useRef(store); if (!storeRef.current) { storeRef.current = createStore(); } - useHydrateAtoms(initialValues, { store: storeRef.current }); + useHydrateAtoms(initialValues as any, { store: storeRef.current }); return ( {children}