React JS - Hooks

 App.js

import './App.css';
import Cntr from './Cntr';


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


export default App;


Cntr.js


import React, {useState} from 'react';

//use state is used to change the sate of a varibale means update a value with a eventlistner in our DOM. 


export default function Cntr() {

    const [count , setCount] = useState(0);   // const[variable , update value fuction] = useState (variable initialization);
   
    const valinc = () =>{
        
    setCount(count+1);   //set setcount function
    }


    return (
        <div className="col-6 m-auto mt-4">
              <h1 className="text-center">{count}</h1>
              <p className="text-center"><button className="btn btn-primary" onClick={valinc}>Click Now</button></p>
        </div>
    )
}


Index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

    <title>Netflix App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>

  </body>
</html>

মন্তব্যসমূহ

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

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

React Js - Form Submit, Input