Skip to content

Commit a3f9709

Browse files
authored
fix: several type and build errors and fix example type inference (#399)
* fix few type errors and fix example * couple fixes * fix babel
1 parent bebd998 commit a3f9709

File tree

7 files changed

+24
-15
lines changed

7 files changed

+24
-15
lines changed

babel.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ module.exports = {
3030
].replace(/^[^0-9]*/, ''),
3131
},
3232
],
33+
['@babel/plugin-proposal-class-properties', { loose: false }],
3334
].filter(Boolean),
3435
overrides: [
3536
{
36-
exclude: ['./packages/solid-form/**', './packages/svelte-form/**', './packages/vue-form/**'],
37+
exclude: [
38+
'./packages/solid-form/**',
39+
'./packages/svelte-form/**',
40+
'./packages/vue-form/**',
41+
],
3742
presets: ['@babel/react'],
3843
},
3944
{

docs/reference/fieldApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ An object type representing the state of a field.
205205
An object type representing the change and blur event handlers for a field.
206206
207207
- ```tsx
208-
onChange?: (updater: Updater<TData>) => void
208+
onChange?: (value: TData) => void
209209
```
210210
- An optional function to further handle the change event.
211211
- ```tsx
@@ -235,7 +235,7 @@ An object type representing the change and blur event handlers for a field.
235235
```
236236
- The current value of the field.
237237
- ```tsx
238-
onChange: (updater: Updater<TData>) => void
238+
onChange: (value: TData) => void
239239
```
240240
- A function to handle the change event.
241241
- ```tsx

examples/react/simple/src/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ export default function App() {
181181
/>
182182
</div> */}
183183
<form.Subscribe
184-
selector={(state) => [state.canSubmit, state.isSubmitting]}
185-
children={([canSubmit, isSubmitting]) => (
186-
<button type="submit" disabled={!canSubmit}>
187-
{isSubmitting ? "..." : "Submit"}
188-
</button>
189-
)}
184+
{...{
185+
// TS bug - inference isn't working with props, so use object
186+
selector: (state) =>
187+
[state.canSubmit, state.isSubmitting] as const,
188+
children: ([canSubmit, isSubmitting]) => (
189+
<button type="submit" disabled={!canSubmit}>
190+
{isSubmitting ? "..." : "Submit"}
191+
</button>
192+
),
193+
}}
190194
/>
191195
</form>
192196
</form.Provider>

packages/form-core/src/FieldApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export type UserInputProps = {
5858

5959
export type ChangeProps<TData> = {
6060
value: TData
61-
onChange: (updater: Updater<TData>) => void
61+
onChange: (value: TData) => void
6262
onBlur: (event: any) => void
6363
}
6464

packages/form-core/src/FormApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class FormApi<TFormData> {
209209
return Promise.all(fieldValidationPromises)
210210
}
211211

212-
validateForm = async () => {}
212+
// validateForm = async () => {}
213213

214214
handleSubmit = async (e: FormSubmitEvent) => {
215215
e.preventDefault()
@@ -248,7 +248,7 @@ export class FormApi<TFormData> {
248248
}
249249

250250
// Run validation for the form
251-
await this.validateForm()
251+
// await this.validateForm()
252252

253253
if (!this.state.isValid) {
254254
done()

packages/react-form/src/useField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function useField<TData, TFormData>(
5757
fieldApi.update({ ...opts, form: formApi })
5858

5959
useStore(
60-
fieldApi.store,
60+
fieldApi.store as any,
6161
opts.mode === 'array'
6262
? (state: any) => {
6363
return [state.meta, Object.keys(state.value || []).length]

packages/react-form/src/useForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
5757
selector,
5858
) => {
5959
// eslint-disable-next-line react-hooks/rules-of-hooks
60-
return useStore(api.store, selector) as any
60+
return useStore(api.store as any, selector as any) as any
6161
}
6262
api.Subscribe = (
6363
// @ts-ignore
@@ -66,7 +66,7 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
6666
return functionalUpdate(
6767
props.children,
6868
// eslint-disable-next-line react-hooks/rules-of-hooks
69-
useStore(api.store, props.selector),
69+
useStore(api.store as any, props.selector as any),
7070
) as any
7171
}
7272

0 commit comments

Comments
 (0)