diff --git a/packages/design/src/Form/index.tsx b/packages/design/src/Form/index.tsx index b95919e7..a8c3c968 100644 --- a/packages/design/src/Form/index.tsx +++ b/packages/design/src/Form/index.tsx @@ -1,5 +1,5 @@ import deepEqual from 'deep-equal'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { @@ -59,7 +59,7 @@ const usePrompt = ( const prompt = createPrompt(config, result.data, { validate: true }); setPrompt(prompt); }; - return { prompt, updatePrompt }; + return { prompt, setPrompt, updatePrompt }; }; export default function Form({ @@ -76,12 +76,18 @@ export default function Form({ const initialPrompt = createPrompt(context.config, session, { validate: false, }); - const { prompt, updatePrompt } = usePrompt( + const { prompt, setPrompt, updatePrompt } = usePrompt( initialPrompt, context.config, session ); + // So the preview view can update the session, regen the prompt. + // This feels smelly. + useEffect(() => { + setPrompt(initialPrompt); + }, [initialPrompt]); + const formMethods = useForm>({}); /** @@ -91,6 +97,7 @@ export default function Form({ updatePrompt(allFormData); }, [allFormData]); */ + return (
diff --git a/packages/design/src/FormManager/FormEdit/Preview.tsx b/packages/design/src/FormManager/FormEdit/Preview.tsx index e06aac4c..3ee3c8da 100644 --- a/packages/design/src/FormManager/FormEdit/Preview.tsx +++ b/packages/design/src/FormManager/FormEdit/Preview.tsx @@ -24,6 +24,7 @@ export const PreviewForm = () => { uswdsRoot: uiContext.uswdsRoot, }; const disposable = createFormSession(form); // nullSession instead? + return (