From 1cc0985745d30626a1b910fd7368658637bf38ff Mon Sep 17 00:00:00 2001 From: Thomas Roberts Date: Tue, 7 Jun 2022 01:39:07 +0100 Subject: [PATCH] Update useValidation to use the data store --- .../js/base/context/hooks/use-validation.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/assets/js/base/context/hooks/use-validation.ts b/assets/js/base/context/hooks/use-validation.ts index 5489a41d68b..bae375b3d87 100644 --- a/assets/js/base/context/hooks/use-validation.ts +++ b/assets/js/base/context/hooks/use-validation.ts @@ -6,27 +6,31 @@ import type { ValidationData, ValidationContextError, } from '@woocommerce/type-defs/contexts'; - -/** - * Internal dependencies - */ -import { useValidationContext } from '../providers/validation/'; +import { useDispatch, useSelect } from '@wordpress/data'; +import { VALIDATION_STORE_KEY } from '@woocommerce/block-data'; /** * Custom hook for setting for adding errors to the validation system. */ export const useValidation = (): ValidationData => { const { - hasValidationErrors, - getValidationError, clearValidationError, hideValidationError, setValidationErrors, - } = useValidationContext(); + } = useDispatch( VALIDATION_STORE_KEY ); + const { hasValidationErrors, getValidationError } = useSelect( + ( select ) => { + const store = select( VALIDATION_STORE_KEY ); + return { + hasValidationErrors: store.hasValidationErrors, + getValidationError: store.getValidationError(), + }; + } + ); const prefix = 'extensions-errors'; return { - hasValidationErrors, + hasValidationErrors: hasValidationErrors(), getValidationError: useCallback( ( validationErrorId: string ) => getValidationError( `${ prefix }-${ validationErrorId }` ),