Skip to content

Commit

Permalink
Add formId param in useFormValues, useInitialValues and useFormValues…
Browse files Browse the repository at this point in the history
…AndExtraInfos
  • Loading branch information
nikhilag committed Apr 12, 2024
1 parent c71f7d0 commit 88a1897
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-recoil-form",
"version": "0.8.0",
"version": "0.8.1",
"license": "MIT",
"author": "Wit By Bit",
"main": "dist/index.js",
Expand Down
20 changes: 13 additions & 7 deletions src/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,26 @@ export function useIsDirty(options?: IIsDirtyProps) {
return !isDeepEqual(initialValues, updatedFormValues);
}

export function useFormValues() {
const formId = useContext(FormIdContext);
export function useFormValues(params?: { formId?: string }) {
const { formId: overrideFormId } = params ?? {};
const defaultFormId = useContext(FormIdContext);
const formId = overrideFormId ?? defaultFormId;
const { values: formValues } = useRecoilValue(formValuesAtom(formId));
return formValues;
}

export function useFormValuesAndExtraInfos() {
const formId = useContext(FormIdContext);
export function useFormValuesAndExtraInfos(params?: { formId?: string }) {
const { formId: overrideFormId } = params ?? {};
const defaultFormId = useContext(FormIdContext);
const formId = overrideFormId ?? defaultFormId;
const { values, extraInfos } = useRecoilValue(formValuesAtom(formId));
return {values, extraInfos};
return { values, extraInfos };
}

export function useInitialValues() {
const formId = useContext(FormIdContext);
export function useInitialValues(params?: { formId?: string }) {
const { formId: overrideFormId } = params ?? {};
const defaultFormId = useContext(FormIdContext);
const formId = overrideFormId ?? defaultFormId;
const { values } = useRecoilValue(formInitialValuesAtom(formId));
return values;
}
Expand Down

0 comments on commit 88a1897

Please sign in to comment.