File tree Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { Dispatch , SetStateAction , useCallback } from 'react' ;
2
2
import produceState , { StateProducerRecipe } from '../utils/produceState' ;
3
3
4
- const useStateProducer = < S extends object > ( setState : Dispatch < SetStateAction < S > > ) => {
4
+ const useStateProducer = < S > ( setState : Dispatch < SetStateAction < S > > ) => {
5
5
return useCallback (
6
6
( recipe : StateProducerRecipe < S > ) => {
7
7
produceState ( setState , recipe ) ;
Original file line number Diff line number Diff line change 1
1
import { Dispatch , SetStateAction } from 'react' ;
2
2
import produce , { Draft } from 'immer' ;
3
- import { Nothing } from 'immer/src/internal' ;
4
3
5
- type ValidRecipeReturnType < State > = State | void | undefined | ( State extends undefined ? Nothing : never ) ;
4
+ type RecipeReturnType < S > = S | void | undefined ;
5
+ export type StateProducerRecipe < S > = < D extends Draft < S > > ( draft : D ) => RecipeReturnType < D > ;
6
6
7
- type RecipeReturnType < State > = ValidRecipeReturnType < State > | Promise < ValidRecipeReturnType < State > > ;
8
-
9
- export type StateProducerRecipe < S > = ( draft : Draft < S > ) => RecipeReturnType < Draft < S > > ;
10
-
11
- const produceState = < S extends object > (
7
+ const produceState = < S > (
12
8
setState : Dispatch < SetStateAction < S > > ,
13
9
recipe : StateProducerRecipe < S >
14
10
) : void | Promise < void > => {
15
11
setState ( ( state ) => {
16
- return produce ( state , recipe as any ) ;
12
+ return produce ( state , recipe ) ;
17
13
} ) ;
18
14
} ;
19
15
You can’t perform that action at this time.
0 commit comments