1
- import { Fragment , useEffect , useState } from 'react' ;
1
+ import { Fragment , useEffect , useRef , useState } from 'react' ;
2
2
3
3
import SelectField from 'sentry/components/forms/fields/selectField' ;
4
4
import type { Organization } from 'sentry/types/organization' ;
@@ -29,6 +29,11 @@ export default function ForkCustomerAction({
29
29
onConfirm,
30
30
setConfirmCallback,
31
31
} : Props ) {
32
+ // TODO: We should make sure that `setConfirmCallback` is a stable function
33
+ // before passing it in here. But because it's not memoized right now, we
34
+ // need to store it in a ref between renders.
35
+ const onConfirmRef = useRef ( setConfirmCallback ) ;
36
+
32
37
const [ regionUrl , setRegionUrl ] = useState ( '' ) ;
33
38
const api = useApi ( { persistInFlight : true } ) ;
34
39
const navigate = useNavigate ( ) ;
@@ -57,8 +62,8 @@ export default function ForkCustomerAction({
57
62
} ) ;
58
63
59
64
useEffect ( ( ) => {
60
- setConfirmCallback ( mutate ) ;
61
- } , [ mutate , setConfirmCallback ] ) ;
65
+ onConfirmRef . current ( mutate ) ;
66
+ } , [ mutate ] ) ;
62
67
63
68
const currentRegionData = getRegionDataFromOrganization ( organization ) ;
64
69
const regionChoices = getRegionChoices ( currentRegionData ? [ currentRegionData ] : [ ] ) ;
@@ -76,7 +81,7 @@ export default function ForkCustomerAction({
76
81
stacked
77
82
required
78
83
value = { regionUrl }
79
- onChange = { ( val : any ) => setRegionUrl ( val ) }
84
+ onChange = { setRegionUrl }
80
85
/>
81
86
</ Fragment >
82
87
) ;
0 commit comments