React input field with button example

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To input field with button, put the <input type="text" value={val} /> class to input field with button example.

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

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

App.js

 import React, { useState } from "react"

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

   return (
     <div>
     <h4>React input field with button example</h4>
       <input type="text" value={val} />
       <button onClick={() => setVal(() => "")}>button</button>
     </div>
   );
 }

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, Button

All the best 👍

Follow me on Twitter