fix(build): a workaround for ESM for use-sync-external-store (#953)

This commit is contained in:
Daishi Kato 2022-07-17 22:03:52 +09:00 committed by GitHub
parent 93ee10341e
commit 28e9614b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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> = S extends { getState: () => infer T } ? T : never
type WithReact<S extends StoreApi<State>> = S & {