From 75762b2acd4392a8702a7f59287ce0770f1ea499 Mon Sep 17 00:00:00 2001 From: daishi Date: Wed, 11 May 2022 18:14:43 +0900 Subject: [PATCH] fix(build): a workaround for ESM for use-sync-external-store --- src/react.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/react.ts b/src/react.ts index 504b82ad50..b05b22f77a 100644 --- a/src/react.ts +++ b/src/react.ts @@ -1,5 +1,9 @@ import { useDebugValue } from 'react' -import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector' +// import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector' +// This doesn't work in ESM, because use-sync-external-store only exposes CJS. +// See: https://github.com/pmndrs/valtio/issues/452 +// The following is a workaround until ESM is supported. +import useSyncExternalStoreExports from 'use-sync-external-store/shim/with-selector' import createStore, { EqualityChecker, Mutate, @@ -10,6 +14,8 @@ import createStore, { StoreMutatorIdentifier, } from './vanilla' +const { useSyncExternalStoreWithSelector } = useSyncExternalStoreExports + type ExtractState = S extends { getState: () => infer T } ? T : never type WithReact> = S & {