Frustrated by Formik? Here's a simpler way to do forms in React

Is this you?

I've tried so many different things I've found online

Holy crap it works now, such a small problem I've lost hours to :(

All I want to do is a simple thing, this is all so unnecessarily complex

Try using react-hook-form.

React-hook-form is different, because it (mostly) keeps its state in the DOM (like classic HTML form elements).

Here's an example of a single field form in react-hook form (taken from their docs):

import React from 'react';
import { useForm } from 'react-hook-form';
const Example = () => {
const { handleSubmit, register, errors } = useForm();
const onSubmit = (values) => console.log(values);
return (
<form onSubmit={handleSubmit(onSubmit)}>
required: 'Required',
pattern: {
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
message: 'invalid email address',
{ &&}
validate: (value) => value !== 'admin' || 'Nice try!',
{errors.username && errors.username.message}
<button type="submit">Submit</button>

Compare that to your existing form code. I don't know about you, but my React forms with Formik would have twice as many lines of code to achieve the same thing.

You'll notice that it's using ref, rather than tracking state within the library. Since moving to react-hook-form, I no longer have to worry about state not syncing correctly in huge forms.

Everything just works as expected, and my code is much simpler too.

(Shameless plug for the React app I'm working on below)

Knowing your React app is still online can be a pain

The React apps we build are the engines that run businesses, so it's a pretty big deal if they break. OnlineOrNot automatically checks your React app as often as every 60 seconds to see if everything is still working as expected.

OnlineOrNot isn't just for React though - it lets you keep track of your whole web presence, from your marketing website, to the React frontend, all the way back to the API sending it data.

You get sent alerts via Slack, Discord, Email, or SMS when things break, before your users notice - start monitoring for free.