ReactJS DOM Events Application
ReactJS DOM Events Application
This document provides the source code for a simple ReactJS application that demonstrates the use
of various DOM events such as onClick, onChange, and onKeyUp. The application captures user
App.js
import React, { useState } from "react";
function App() {
setInputValue(event.target.value);
};
setKeyPressed(event.key);
};
};
return (
<div style={{ padding: "20px", fontFamily: "Arial, sans-serif" }}>
<label>
<input
type="text"
value={inputValue}
onChange={handleInputChange}
onKeyUp={handleKeyUp}
/>
</label>
</div>
{keyPressed && (
)}
<button
onClick={handleButtonClick}
style={{
fontSize: "16px",
cursor: "pointer",
backgroundColor: "#007BFF",
color: "white",
border: "none",
borderRadius: "5px",
}}
>
Greet Me
</button>
{message && (
{message}
</p>
)}
</div>
);
index.js
import React from "react";
import "./index.css";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
index.css
body {
margin: 0;
padding: 0;
background-color: #f4f4f4;