Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose a FormFragment component for use in complex components #129

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testTimeout: process.env.JEST_TIMEOUT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice for debugging

? parseInt(process.env.JEST_TIMEOUT)
: undefined,
testEnvironment: "jsdom",
testPathIgnorePatterns: ["utils", "lib"],
restoreMocks: true,
Expand Down
9 changes: 7 additions & 2 deletions src/FieldContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export function FieldContextProvider({
);
}

export function useMaybeFieldName() {
Copy link
Collaborator Author

@scamden scamden Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let us automatically derive the name from context if there are any Fields already provided above us

const context = useContext(FieldContext);
return context?.name;
}

function useContextProt(name: string) {
const context = useContext(FieldContext);
if (!context)
Expand Down Expand Up @@ -106,7 +111,7 @@ export function useTsController<FieldType extends any>() {
? DeepPartial<FieldType> | undefined
: FieldType | undefined;
// Just gives better types to useController
const controller = useController(context) as any as Omit<
const controller = useController(context) as unknown as Omit<
UseControllerReturn,
"field"
> & {
Expand Down Expand Up @@ -471,4 +476,4 @@ export function useNumberFieldInfo() {
},
"useNumberFieldInfo"
);
}
}
Loading