@@ -20,14 +20,20 @@ import {
20
20
useContext ,
21
21
useDebugValue
22
22
} from 'preact/hooks' ;
23
+ import {
24
+ useInsertionEffect ,
25
+ startTransition ,
26
+ useDeferredValue ,
27
+ useSyncExternalStore ,
28
+ useTransition
29
+ } from './hooks' ;
23
30
import { PureComponent } from './PureComponent' ;
24
31
import { memo } from './memo' ;
25
32
import { forwardRef } from './forwardRef' ;
26
33
import { Children } from './Children' ;
27
34
import { Suspense , lazy } from './suspense' ;
28
35
import { SuspenseList } from './suspense-list' ;
29
36
import { createPortal } from './portals' ;
30
- import { is } from './util' ;
31
37
import {
32
38
hydrate ,
33
39
render ,
@@ -143,77 +149,9 @@ const flushSync = (callback, arg) => callback(arg);
143
149
*/
144
150
const StrictMode = Fragment ;
145
151
146
- export function startTransition ( cb ) {
147
- cb ( ) ;
148
- }
149
-
150
- export function useDeferredValue ( val ) {
151
- return val ;
152
- }
153
-
154
- export function useTransition ( ) {
155
- return [ false , startTransition ] ;
156
- }
157
-
158
- // TODO: in theory this should be done after a VNode is diffed as we want to insert
159
- // styles/... before it attaches
160
- export const useInsertionEffect = useLayoutEffect ;
161
-
162
152
// compat to react-is
163
153
export const isElement = isValidElement ;
164
154
165
- /**
166
- * This is taken from https://github.com/facebook/react/blob/main/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L84
167
- * on a high level this cuts out the warnings, ... and attempts a smaller implementation
168
- * @typedef {{ _value: any; _getSnapshot: () => any } } Store
169
- */
170
- export function useSyncExternalStore ( subscribe , getSnapshot ) {
171
- const value = getSnapshot ( ) ;
172
-
173
- /**
174
- * @typedef {{ _instance: Store } } StoreRef
175
- * @type {[StoreRef, (store: StoreRef) => void] }
176
- */
177
- const [ { _instance } , forceUpdate ] = useState ( {
178
- _instance : { _value : value , _getSnapshot : getSnapshot }
179
- } ) ;
180
-
181
- useLayoutEffect ( ( ) => {
182
- _instance . _value = value ;
183
- _instance . _getSnapshot = getSnapshot ;
184
-
185
- if ( didSnapshotChange ( _instance ) ) {
186
- forceUpdate ( { _instance } ) ;
187
- }
188
- } , [ subscribe , value , getSnapshot ] ) ;
189
-
190
- useEffect ( ( ) => {
191
- if ( didSnapshotChange ( _instance ) ) {
192
- forceUpdate ( { _instance } ) ;
193
- }
194
-
195
- return subscribe ( ( ) => {
196
- if ( didSnapshotChange ( _instance ) ) {
197
- forceUpdate ( { _instance } ) ;
198
- }
199
- } ) ;
200
- } , [ subscribe ] ) ;
201
-
202
- return value ;
203
- }
204
-
205
- /** @type {(inst: Store) => boolean } */
206
- function didSnapshotChange ( inst ) {
207
- const latestGetSnapshot = inst . _getSnapshot ;
208
- const prevValue = inst . _value ;
209
- try {
210
- const nextValue = latestGetSnapshot ( ) ;
211
- return ! is ( prevValue , nextValue ) ;
212
- } catch ( error ) {
213
- return true ;
214
- }
215
- }
216
-
217
155
export * from 'preact/hooks' ;
218
156
export {
219
157
version ,
@@ -237,6 +175,11 @@ export {
237
175
memo ,
238
176
forwardRef ,
239
177
flushSync ,
178
+ useInsertionEffect ,
179
+ startTransition ,
180
+ useDeferredValue ,
181
+ useSyncExternalStore ,
182
+ useTransition ,
240
183
// eslint-disable-next-line camelcase
241
184
unstable_batchedUpdates ,
242
185
StrictMode ,
0 commit comments