React Js - Events With Hooks

 App.js

import React from "react";
import './App.css';
import ReactDom from "react-dom";
import Events from './events';


function App() {
 return(
   <>
   <Events/>
   </>
 );
}


export default App;


Events.js


import React, {useState} from 'react';

export default function Events() {   //react components name should start with upper case
    const purple = '#8e44ad';
    const [bg, setBg] = useState(purple);  
    const [named, setName] = useState("Click Me");

    const bgChange = () =>{
        let newBg = "#34495e";
        setBg(newBg);
        let newName = "UFF!";
        setName(newName);
      //  console.log("clicked");
    }

    const bgBack = () =>{
        setBg(purple);
        setName("Ayyo!");
    }

    return (
        <div className="main" style={{backgroundColor : bg}}>
            <p className="text-center pt-5">
            <button className="btn btn-primary" onDoubleClick={bgBack} onClick={bgChange}>{named}</button></p>
        </div>
    )
}

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

React Js Cards (Props, Array, Mapping, Rendaring)

React JS - Hooks

React Js - Form Submit, Input