@tamagui/core 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,38 @@
1
- import React, { useCallback } from 'react'
1
+ import React, { startTransition, useCallback } from 'react'
2
2
 
3
3
  import { DebugProp } from '../types'
4
4
 
5
5
  export function useShallowSetState<State extends Object>(
6
6
  setter: React.Dispatch<React.SetStateAction<State>>,
7
+ transition?: boolean,
7
8
  debug?: DebugProp,
8
9
  debugName?: string
9
10
  ) {
10
11
  return useCallback(
11
12
  (next: Partial<State>) => {
12
- setter((prev) => {
13
- for (const key in next) {
14
- if (prev[key] !== next[key]) {
15
- if (process.env.NODE_ENV === 'development') {
16
- if (debug === 'verbose') {
17
- // eslint-disable-next-line no-console
18
- console.log(` ▲ setState ${debugName}`, next)
13
+ const run = () => {
14
+ setter((prev) => {
15
+ for (const key in next) {
16
+ if (prev[key] !== next[key]) {
17
+ if (process.env.NODE_ENV === 'development') {
18
+ if (debug === 'verbose') {
19
+ // eslint-disable-next-line no-console
20
+ console.log(` ▲ setState ${debugName}`, next)
21
+ }
19
22
  }
23
+ return { ...prev, ...next }
20
24
  }
21
- return { ...prev, ...next }
22
25
  }
23
- }
24
- return prev
25
- })
26
+ return prev
27
+ })
28
+ }
29
+ if (transition) {
30
+ startTransition(() => {
31
+ run()
32
+ })
33
+ } else {
34
+ run()
35
+ }
26
36
  },
27
37
  [setter]
28
38
  )
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { DebugProp } from '../types';
3
- export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>, debug?: DebugProp, debugName?: string): (next: Partial<State>) => void;
3
+ export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>, transition?: boolean, debug?: DebugProp, debugName?: string): (next: Partial<State>) => void;
4
4
  //# sourceMappingURL=useShallowSetState.d.ts.map