Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reset Uncontrolled Forms by Forcing React to Rebuild the DOM.
import React, { useState, createRef } from "react";
const Form = () => {
const emailRef = createRef<HTMLInputElement>()
return (
<input type="text" ref={emailRef}/>
onClick={() => {
// This check is necessary because in theory we could hit this
// code even though React is still rebuilding the DOM.
if (emailRef.current) {
window.alert(`Your email is "${emailRef.current.value}"`)
export {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment