Update `useQueryStateByContext` to remove need for context when setting values (https://github.com/woocommerce/woocommerce-blocks/pull/1239)
* Don't require context for set * Update tests
This commit is contained in:
parent
6e2978413e
commit
2f3c4623b7
|
@ -145,7 +145,9 @@ describe( 'Testing Query State Hooks', () => {
|
|||
act( () => {
|
||||
setQueryState( { foo: 'bar' } );
|
||||
} );
|
||||
expect( action ).toHaveBeenCalledWith( { foo: 'bar' } );
|
||||
expect( action ).toHaveBeenCalledWith( 'test-context', {
|
||||
foo: 'bar',
|
||||
} );
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
|
|
@ -37,7 +37,14 @@ export const useQueryStateByContext = ( context ) => {
|
|||
},
|
||||
[ context ]
|
||||
);
|
||||
const { setValueForQueryContext: setQueryState } = useDispatch( storeKey );
|
||||
const { setValueForQueryContext } = useDispatch( storeKey );
|
||||
const setQueryState = useCallback(
|
||||
( value ) => {
|
||||
setValueForQueryContext( context, value );
|
||||
},
|
||||
[ context ]
|
||||
);
|
||||
|
||||
return [ queryState, setQueryState ];
|
||||
};
|
||||
|
||||
|
@ -115,7 +122,7 @@ export const useSynchronizedQueryState = ( synchronizedQuery, context ) => {
|
|||
const isInitialized = useRef( false );
|
||||
// update queryState anytime incoming synchronizedQuery changes
|
||||
useEffect( () => {
|
||||
setQueryState( context, {
|
||||
setQueryState( {
|
||||
...queryState,
|
||||
...currentSynchronizedQuery,
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue