fix: complete form factory functionality, docs

This commit is contained in:
Tanner Linsley
2023-05-01 10:59:37 -06:00
parent b274bccf3d
commit c444704ae3
7 changed files with 103 additions and 51 deletions

View File

@@ -54,8 +54,6 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
return api
})
// React.useEffect(() => formApi.mount(), [])
return formApi as any
}
@@ -66,7 +64,7 @@ export type FormProps = React.HTMLProps<HTMLFormElement> & {
export type FormComponent = (props: FormProps) => any
export function createFormComponent(formApi: FormApi<any>) {
function createFormComponent(formApi: FormApi<any>) {
const Form: FormComponent = ({ children, noFormElement, ...rest }) => {
const isSubmitting = formApi.useStore((state) => state.isSubmitting)
@@ -80,26 +78,6 @@ export function createFormComponent(formApi: FormApi<any>) {
disabled={isSubmitting}
{...rest}
>
{formApi.options.debugForm ? (
<div
style={{
margin: '2rem 0',
}}
>
<div
style={{
fontWeight: 'bolder',
}}
>
Form State
</div>
<pre>
<code>
{JSON.stringify(formApi, safeStringifyReplace(), 2)}
</code>
</pre>
</div>
) : null}
{children}
</form>
)}
@@ -109,16 +87,3 @@ export function createFormComponent(formApi: FormApi<any>) {
return Form
}
function safeStringifyReplace() {
const set = new Set()
return (_key: string, value: any) => {
if (typeof value === 'object' || Array.isArray(value)) {
if (set.has(value)) {
return '(circular value)'
}
set.add(value)
}
return typeof value === 'function' ? undefined : value
}
}