Programming Exercises

Create a React form with an input field and a submit button that logs the input value to the console.

Easy

Problem Statement

Create a React form with an input field and a submit button that logs the input value to the console.

Sample Input

Hardcoded initial input value: 'React'

Sample Output

Console log: Input value: React (when the form is submitted)

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import React, { useState } from "react"; const InputForm = () => { const [inputValue, setInputValue] = useState("React"); const handleSubmit = (e) => { e.preventDefault(); // Log the input value to the console }; return ( <form onSubmit={handleSubmit}> <input type="text" value={inputValue} onChange={(e) => setInputValue(e.target.value)} /> <button type="submit">Submit</button> </form> ); }; export default InputForm;
Log in or sign up to run or submit your code.Log inSign up
Input
Hardcoded initial input value: 'React'
Expected Output
Console log: Input value: React (when the form is submitted)