Skip to content

Commit 3dce942

Browse files
JoviDeCroockkitten
authored andcommitted
add useTransition and useDeferredValue (#36)
* add useTransition and useDeferredValue * alter the return value of useTransition
1 parent 2fcea59 commit 3dce942

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/internals/__tests__/dispatcher.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,18 @@ describe('useCallback', () => {
2929
expect(Dispatcher.useCallback(fn)).toBe(fn)
3030
})
3131
})
32+
33+
describe('useTransition', () => {
34+
it('returns noop and false', () => {
35+
const result = Dispatcher.useTransition()
36+
expect(typeof result[0]).toBe('function')
37+
expect(result[1]).toBe(false)
38+
})
39+
})
40+
41+
describe('useDeferredValue', () => {
42+
it('returns itself', () => {
43+
const value = {}
44+
expect(Dispatcher.useDeferredValue(value)).toBe(value)
45+
})
46+
})

src/internals/dispatcher.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ function useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {
306306

307307
function noop(): void {}
308308

309+
function useTransition(): [(callback: () => void) => void, boolean] {
310+
const startTransition = callback => {
311+
callback()
312+
}
313+
return [startTransition, false]
314+
}
315+
316+
function useDeferredValue<T>(input: T): T {
317+
return input
318+
}
319+
309320
export const Dispatcher = {
310321
readContext,
311322
useContext,
@@ -314,6 +325,8 @@ export const Dispatcher = {
314325
useRef,
315326
useState,
316327
useCallback,
328+
useTransition,
329+
useDeferredValue,
317330
// ignore useLayout effect completely as usage of it will be caught
318331
// in a subsequent render pass
319332
useLayoutEffect: noop,

0 commit comments

Comments
 (0)