()
| 56 | : T |
| 57 | |
| 58 | export function createFormHookContexts() { |
| 59 | // We should never hit the `null` case here |
| 60 | const fieldContext = createContext<Accessor<AnyFieldApi>>( |
| 61 | null as unknown as Accessor<AnyFieldApi>, |
| 62 | ) |
| 63 | |
| 64 | function useFieldContext<TData>() { |
| 65 | const field = useContext(fieldContext) |
| 66 | |
| 67 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 68 | if (!field) { |
| 69 | throw new Error( |
| 70 | '`fieldContext` only works when within a `fieldComponent` passed to `createFormHook`', |
| 71 | ) |
| 72 | } |
| 73 | |
| 74 | return field as Accessor< |
| 75 | FieldApi< |
| 76 | any, |
| 77 | string, |
| 78 | TData, |
| 79 | any, |
| 80 | any, |
| 81 | any, |
| 82 | any, |
| 83 | any, |
| 84 | any, |
| 85 | any, |
| 86 | any, |
| 87 | any, |
| 88 | any, |
| 89 | any, |
| 90 | any, |
| 91 | any, |
| 92 | any, |
| 93 | any, |
| 94 | any, |
| 95 | any, |
| 96 | any, |
| 97 | any, |
| 98 | any |
| 99 | > |
| 100 | > |
| 101 | } |
| 102 | |
| 103 | // We should never hit the `null` case here |
| 104 | const formContext = createContext<AnyFormApi>(null as unknown as AnyFormApi) |
| 105 | |
| 106 | function useFormContext() { |
| 107 | const form = useContext(formContext) |
| 108 | |
| 109 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 110 | if (!form) { |
| 111 | throw new Error( |
| 112 | '`formContext` only works when within a `formComponent` passed to `createFormHook`', |
| 113 | ) |
| 114 | } |
| 115 |
no outgoing calls
no test coverage detected