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 11import { Dispatch , SetStateAction , useCallback } from 'react' ;
22import produceState , { StateProducerRecipe } from '../utils/produceState' ;
33
4- const useStateProducer = < S extends object > ( setState : Dispatch < SetStateAction < S > > ) => {
4+ const useStateProducer = < S > ( setState : Dispatch < SetStateAction < S > > ) => {
55 return useCallback (
66 ( recipe : StateProducerRecipe < S > ) => {
77 produceState ( setState , recipe ) ;
Original file line number Diff line number Diff line change 11import { Dispatch , SetStateAction } from 'react' ;
22import produce , { Draft } from 'immer' ;
3- import { Nothing } from 'immer/src/internal' ;
43
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 > ;
66
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 > (
128 setState : Dispatch < SetStateAction < S > > ,
139 recipe : StateProducerRecipe < S >
1410) : void | Promise < void > => {
1511 setState ( ( state ) => {
16- return produce ( state , recipe as any ) ;
12+ return produce ( state , recipe ) ;
1713 } ) ;
1814} ;
1915
You can’t perform that action at this time.
0 commit comments