React input field with clear button example

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To clear an input field with React, we can set the value an empty button string.

Today, I am going to show you. how to input field with clear button in react js with code example.

Let’s look at the following example to understand how it basically works:


import React, { useState } from "react";

export default function App() {
  const [val, setVal] = useState();

  return (
      <input type="text" value={val} />
      <button onClick={() => setVal(() => "")}>Reset</button>

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Check the output of the above code example.

React, Input, Clean, Button

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts