1111 */
1212
1313import { act , render } from '@react-spectrum/test-utils-internal' ;
14- import React from 'react' ;
14+ import React , { useEffect } from 'react' ;
1515import { useCheckboxGroupState } from '../' ;
1616
1717describe ( 'useCheckboxGroupState' , ( ) => {
@@ -107,7 +107,9 @@ describe('useCheckboxGroupState', () => {
107107 let setValue : ( value : string [ ] ) => void ;
108108 function Test ( ) {
109109 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' ] } ) ;
110- setValue = state . setValue ;
110+ useEffect ( ( ) => {
111+ setValue = state . setValue ;
112+ } , [ state ] ) ;
111113 return < > { state . value . join ( ', ' ) } </ > ;
112114 }
113115 const { container} = render ( < Test /> ) ;
@@ -128,7 +130,9 @@ describe('useCheckboxGroupState', () => {
128130
129131 function Test ( ) {
130132 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' ] , onChange : onChangeSpy } ) ;
131- setValue = state . setValue ;
133+ useEffect ( ( ) => {
134+ setValue = state . setValue ;
135+ } , [ state ] ) ;
132136 return < > { state . value . join ( ', ' ) } </ > ;
133137 }
134138
@@ -145,7 +149,9 @@ describe('useCheckboxGroupState', () => {
145149 let addValue : ( value : string ) => void ;
146150 function Test ( ) {
147151 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' ] } ) ;
148- addValue = state . addValue ;
152+ useEffect ( ( ) => {
153+ addValue = state . addValue ;
154+ } , [ state ] ) ;
149155 return < > { state . value . join ( ', ' ) } </ > ;
150156 }
151157 const { container} = render ( < Test /> ) ;
@@ -161,7 +167,9 @@ describe('useCheckboxGroupState', () => {
161167 let addValue : ( value : string ) => void ;
162168 function Test ( ) {
163169 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' ] } ) ;
164- addValue = state . addValue ;
170+ useEffect ( ( ) => {
171+ addValue = state . addValue ;
172+ } , [ state ] ) ;
165173 return < > { state . value . join ( ', ' ) } </ > ;
166174 }
167175 const { container} = render ( < Test /> ) ;
@@ -180,7 +188,9 @@ describe('useCheckboxGroupState', () => {
180188 let removeValue : ( value : string ) => void ;
181189 function Test ( ) {
182190 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' , 'qwe' ] } ) ;
183- removeValue = state . removeValue ;
191+ useEffect ( ( ) => {
192+ removeValue = state . removeValue ;
193+ } , [ state ] ) ;
184194 return < > { state . value . join ( ', ' ) } </ > ;
185195 }
186196 const { container} = render ( < Test /> ) ;
@@ -196,7 +206,9 @@ describe('useCheckboxGroupState', () => {
196206 let toggleValue : ( value : string ) => void ;
197207 function Test ( ) {
198208 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' , 'qwe' ] } ) ;
199- toggleValue = state . toggleValue ;
209+ useEffect ( ( ) => {
210+ toggleValue = state . toggleValue ;
211+ } , [ state ] ) ;
200212 return < > { state . value . join ( ', ' ) } </ > ;
201213 }
202214 const { container} = render ( < Test /> ) ;
@@ -218,7 +230,10 @@ describe('useCheckboxGroupState', () => {
218230 let toggleValue : ( value : string ) => void ;
219231 function Test ( ) {
220232 const state = useCheckboxGroupState ( { defaultValue : [ 'foo' , 'qwe' ] } ) ;
221- toggleValue = state . toggleValue ;
233+ useEffect ( ( ) => {
234+ toggleValue = state . toggleValue ;
235+ } , [ state ] ) ;
236+
222237 return < > { state . value . join ( ', ' ) } </ > ;
223238 }
224239 const { container} = render ( < Test /> ) ;
@@ -239,10 +254,12 @@ describe('useCheckboxGroupState', () => {
239254
240255 function Test ( ) {
241256 const state = useCheckboxGroupState ( { isReadOnly : true , defaultValue : [ 'test' ] } ) ;
242- addValue = state . addValue ;
243- removeValue = state . removeValue ;
244- toggleValue = state . toggleValue ;
245- setValue = state . setValue ;
257+ useEffect ( ( ) => {
258+ addValue = state . addValue ;
259+ removeValue = state . removeValue ;
260+ toggleValue = state . toggleValue ;
261+ setValue = state . setValue ;
262+ } , [ state ] ) ;
246263
247264 return < > { state . value . join ( ', ' ) } </ > ;
248265 }
@@ -284,10 +301,12 @@ describe('useCheckboxGroupState', () => {
284301
285302 function Test ( ) {
286303 const state = useCheckboxGroupState ( { isDisabled : true , defaultValue : [ 'test' ] } ) ;
287- addValue = state . addValue ;
288- removeValue = state . removeValue ;
289- toggleValue = state . toggleValue ;
290- setValue = state . setValue ;
304+ useEffect ( ( ) => {
305+ addValue = state . addValue ;
306+ removeValue = state . removeValue ;
307+ toggleValue = state . toggleValue ;
308+ setValue = state . setValue ;
309+ } , [ state ] ) ;
291310
292311 return < > { state . value . join ( ', ' ) } </ > ;
293312 }
0 commit comments