From 09178528ed6a9b5129f1900f7aa14d5308c91415 Mon Sep 17 00:00:00 2001 From: Daniel Belcher <47116905+daniel-belcher@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:35:24 -0800 Subject: [PATCH] fix: using formContext hook outside of forms (#340) - fix dependencyWrapper to no longer use RHF hooks outside of generated form context --- .../ui/src/components/RHF/dependencyWrapper.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/services/ui/src/components/RHF/dependencyWrapper.tsx b/src/services/ui/src/components/RHF/dependencyWrapper.tsx index 1664bcb9ed..e2234fb872 100644 --- a/src/services/ui/src/components/RHF/dependencyWrapper.tsx +++ b/src/services/ui/src/components/RHF/dependencyWrapper.tsx @@ -26,7 +26,22 @@ const checkTriggeringValue = ( }); }; -export const DependencyWrapper = ({ +export const DependencyWrapper = ( + props: PropsWithChildren +) => { + // Check for dependencies which won't exist outside of forms + if ( + !props.dependency || + !props.dependency.conditions || + !props.dependency.effect + ) { + return <>{props.children}; + } + + return ; +}; + +const DependencyWrapperHandler = ({ name, dependency, children,