Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/ReactFinalForm.d.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,29 @@ function mutated() {
</Form>
)
}

// with typed form data

const typedOnSubmit = (values: { firstName: string }) => {
console.log(values)
}

function withTypedFormData() {
return (
<Form<{ firstName: string }> onSubmit={typedOnSubmit}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<div>
<label>First Name</label>
<Field
name="firstName"
component="input"
type="text"
placeholder="First Name"
/>
</div>
</form>
)}
</Form>
)
}
8 changes: 6 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export interface RenderableProps<T> {
render?: (props: T) => React.ReactNode
}

export interface FormProps extends Config, RenderableProps<FormRenderProps> {
export interface FormProps<FormData = object>
extends Config<FormData>,
RenderableProps<FormRenderProps> {
subscription?: FormSubscription
decorators?: Decorator[]
initialValuesEqual?: (a?: object, b?: object) => boolean
Copy link

Choose a reason for hiding this comment

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

Shouldn't these also be FormData?

Expand All @@ -94,7 +96,9 @@ export interface FormSpyProps extends RenderableProps<FormSpyRenderProps> {
}

export var Field: React.ComponentType<FieldProps>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice for Field to get the same treatment.

export var Form: React.ComponentType<FormProps>
export class Form<FormData = object> extends React.Component<
Copy link
Contributor

Choose a reason for hiding this comment

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

Form is actually implemented as a function, not as a class, so this type could be misleading couldn't it?

It would suggest I can create instances a la const form = new Form()?

Copy link

Choose a reason for hiding this comment

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

I've been doing this if it helps.

<FormData = object>(
  props: FormProps<FormData>,
) => React.ReactElement<FormProps<FormData>>

Copy link
Member

Choose a reason for hiding this comment

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

FormProps<FormData>
> {}
export var FormSpy: React.ComponentType<FormSpyProps>
export var version: string

Expand Down