Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conform-react)!: return fieldset on useForm hook #78

Merged
merged 3 commits into from
Jan 8, 2023

Conversation

edmundhung
Copy link
Owner

This is a change I have been considering since v0.3. What changed is just calling useFieldset() inside useForm() and return the data as a tuple:

// Before
export default function LoginForm() {
    const form = useForm({
        onValidate({ form, formData }) {
            return validate(formData, schema);
        },
    });
    const { email, password } = useFieldset(form.ref, form.config);

    return (
        <form {...form.props}>
            {/* ... */}
        </form>
    );
}

// After the changes
export default function LoginForm() {
    const [form, { email, password }] = useForm({
        onValidate({ form, formData }) {
            return validate(formData, schema);
        },
    });

    return (
        <form {...form.props}>
            {/* ... */}
        </form>
    );
}

@codesandbox
Copy link

codesandbox bot commented Jan 7, 2023

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@edmundhung edmundhung changed the base branch from main to dev January 7, 2023 20:23
@edmundhung edmundhung changed the title feat(conform-react): return fieldset on useForm hook feat(conform-react)!: return fieldset on useForm hook Jan 7, 2023
@brandonpittman
Copy link
Contributor

Seems like a good change. Saves a bit of boilerplate.

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jan 8, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ee7525f
Status: ✅  Deploy successful!
Preview URL: https://ab837479.conform.pages.dev
Branch Preview URL: https://useform-enhancement.conform.pages.dev

View logs

@edmundhung edmundhung merged commit 2659da7 into dev Jan 8, 2023
@edmundhung edmundhung deleted the useform-enhancement branch January 8, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants