Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

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

Try your code in this preview. Submit marks it done.

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;