Event mini project by Thapa#33
Index.jsx
import React from 'react'
import ReactDOM from 'react-dom';
import "./index.css";
import App from "./App";
ReactDOM.render(<App/>, document.getElementById("root"));
index.css
*{
margin: 0;
padding: 0;
}
div{
width:100%;
height:100vh;
background: rgb(221, 39, 221);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
button{
padding: 12px 20px;
background: #9b59b6;
color: white;
border: 2px solid #ecf0f1;
outline: none;
border-radius: 5px;
text-transform: uppercase;
cursor: pointer;
}
app.jsx
import React, { useState } from 'react';
const App =()=>{
const Purple= "yellow";
const Old="Click Me"
const [bg, setBg] = useState(Purple);
const [name,newName] = useState(Old);
const bgChange=()=>{
let newBg = "Pink";
setBg(newBg);
newName("Help!");
}
const back=()=>{
setBg(Purple);
newName(Old);
}
return(
<>
<div style={{backgroundColor: bg}}>
<button onMouseEnter={bgChange} onDoubleClick={back}> {name}</button>
</div>
</>
)
}
export default App;
Comments
Post a Comment