DEV Community

Cover image for Uninformed: nostalgically simple forms for React & Preact
chrisfrank
chrisfrank

Posted on

3

Uninformed: nostalgically simple forms for React & Preact

Forms in Rails do two useful things automatically that I miss when I'm working in other frameworks:

  1. They submit data without reloading the page.
  2. They disable themselves on submit, so that you can't accidentally submit data twice by double-clicking.

These are great defaults! In a web app in 2019, I should have to write code to disable this behavior -- but I've found myself re-implementing it from scratch in several React projects.

I wrote Uninformed to bring these defaults to the React ecosystem. Here's how to use Uninformed in an app:

import { Form } from 'uninformed';
import React from 'react';

const SignupForm = props => (
  <Form action="/api/signups" onSuccess={props.handleSuccess}>
    <input type="email" name="email" required />
    <input type="submit" value="Sign Up" />
  </Form>
)

That’s it! No onChange handlers, no Input components, just a lightly-enhanced HTML form that disables itself on submit, sends data to a server via an XMLHttpRequest, and re-enables itself after the server responds. When you need more power -- for setting request headers, running input validation, etc -- Uninformed lets you customize its behavior by passing functions as props. See the README for more info.

Uninformed is brand new, and I'd love to hear your ideas for how to improve it! Please feel free to file issues, pull requests, or ask questions in the comments below.

(Cover image by Kelly Sikkema via Unsplash)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
bconfortin profile image
Bruno Goerck Confortin

Awesome job :D

Collapse
 
chrisfrank profile image
chrisfrank

Thanks, Bruno!

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay