mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-07 20:37:48 +00:00
fix: several type and build errors and fix example type inference (#399)
* fix few type errors and fix example * couple fixes * fix babel
This commit is contained in:
@@ -30,10 +30,15 @@ module.exports = {
|
|||||||
].replace(/^[^0-9]*/, ''),
|
].replace(/^[^0-9]*/, ''),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
['@babel/plugin-proposal-class-properties', { loose: false }],
|
||||||
].filter(Boolean),
|
].filter(Boolean),
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
exclude: ['./packages/solid-form/**', './packages/svelte-form/**', './packages/vue-form/**'],
|
exclude: [
|
||||||
|
'./packages/solid-form/**',
|
||||||
|
'./packages/svelte-form/**',
|
||||||
|
'./packages/vue-form/**',
|
||||||
|
],
|
||||||
presets: ['@babel/react'],
|
presets: ['@babel/react'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ An object type representing the state of a field.
|
|||||||
An object type representing the change and blur event handlers for a field.
|
An object type representing the change and blur event handlers for a field.
|
||||||
|
|
||||||
- ```tsx
|
- ```tsx
|
||||||
onChange?: (updater: Updater<TData>) => void
|
onChange?: (value: TData) => void
|
||||||
```
|
```
|
||||||
- An optional function to further handle the change event.
|
- An optional function to further handle the change event.
|
||||||
- ```tsx
|
- ```tsx
|
||||||
@@ -235,7 +235,7 @@ An object type representing the change and blur event handlers for a field.
|
|||||||
```
|
```
|
||||||
- The current value of the field.
|
- The current value of the field.
|
||||||
- ```tsx
|
- ```tsx
|
||||||
onChange: (updater: Updater<TData>) => void
|
onChange: (value: TData) => void
|
||||||
```
|
```
|
||||||
- A function to handle the change event.
|
- A function to handle the change event.
|
||||||
- ```tsx
|
- ```tsx
|
||||||
|
|||||||
@@ -181,12 +181,16 @@ export default function App() {
|
|||||||
/>
|
/>
|
||||||
</div> */}
|
</div> */}
|
||||||
<form.Subscribe
|
<form.Subscribe
|
||||||
selector={(state) => [state.canSubmit, state.isSubmitting]}
|
{...{
|
||||||
children={([canSubmit, isSubmitting]) => (
|
// TS bug - inference isn't working with props, so use object
|
||||||
<button type="submit" disabled={!canSubmit}>
|
selector: (state) =>
|
||||||
{isSubmitting ? "..." : "Submit"}
|
[state.canSubmit, state.isSubmitting] as const,
|
||||||
</button>
|
children: ([canSubmit, isSubmitting]) => (
|
||||||
)}
|
<button type="submit" disabled={!canSubmit}>
|
||||||
|
{isSubmitting ? "..." : "Submit"}
|
||||||
|
</button>
|
||||||
|
),
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</form.Provider>
|
</form.Provider>
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export type UserInputProps = {
|
|||||||
|
|
||||||
export type ChangeProps<TData> = {
|
export type ChangeProps<TData> = {
|
||||||
value: TData
|
value: TData
|
||||||
onChange: (updater: Updater<TData>) => void
|
onChange: (value: TData) => void
|
||||||
onBlur: (event: any) => void
|
onBlur: (event: any) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ export class FormApi<TFormData> {
|
|||||||
return Promise.all(fieldValidationPromises)
|
return Promise.all(fieldValidationPromises)
|
||||||
}
|
}
|
||||||
|
|
||||||
validateForm = async () => {}
|
// validateForm = async () => {}
|
||||||
|
|
||||||
handleSubmit = async (e: FormSubmitEvent) => {
|
handleSubmit = async (e: FormSubmitEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -248,7 +248,7 @@ export class FormApi<TFormData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run validation for the form
|
// Run validation for the form
|
||||||
await this.validateForm()
|
// await this.validateForm()
|
||||||
|
|
||||||
if (!this.state.isValid) {
|
if (!this.state.isValid) {
|
||||||
done()
|
done()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export function useField<TData, TFormData>(
|
|||||||
fieldApi.update({ ...opts, form: formApi })
|
fieldApi.update({ ...opts, form: formApi })
|
||||||
|
|
||||||
useStore(
|
useStore(
|
||||||
fieldApi.store,
|
fieldApi.store as any,
|
||||||
opts.mode === 'array'
|
opts.mode === 'array'
|
||||||
? (state: any) => {
|
? (state: any) => {
|
||||||
return [state.meta, Object.keys(state.value || []).length]
|
return [state.meta, Object.keys(state.value || []).length]
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
|
|||||||
selector,
|
selector,
|
||||||
) => {
|
) => {
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
return useStore(api.store, selector) as any
|
return useStore(api.store as any, selector as any) as any
|
||||||
}
|
}
|
||||||
api.Subscribe = (
|
api.Subscribe = (
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -66,7 +66,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
|
|||||||
return functionalUpdate(
|
return functionalUpdate(
|
||||||
props.children,
|
props.children,
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
useStore(api.store, props.selector),
|
useStore(api.store as any, props.selector as any),
|
||||||
) as any
|
) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user