Tuesday, August 25, 2020

ARRAY HOOK IN REACT JS(V16)

  • Hook let you use state and other React features without writing a class. 
  • Hook doesn't work inside classes.
  • Hook used for function components.
  • Ex.:useState() is a hook function components, it returns an array of two items.

App.jsx

import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import Card from './Cards';
import Sdata from './Sdata';
import "./index.css";

const App = () => {
    let newT = new Date().toLocaleTimeString();
    // Array Hook; setCtime is holding updated value
    // & ctime is holding current value of newT.
    const [ctimesetCtime] = useState(newT); // Array destructuring  

    const UpdateTime = () => {
        newT = new Date().toLocaleTimeString();
        setCtime(newT);
    }
    setInterval(UpdateTime1000)

    return(
        <>
        <h1 className='top_head'> {ctime}<br/> TOP 3 NETFLIX SHOWS</h1>
        {Sdata.map((valindex=> {
            return (
                <Card 
                key = {val.id}
                imgsrc = {val.imgsrc}
                imgname = {val.imgname}
                category = {val.category}
                tit = {val.tit}
                link = {val.link}
                />);
            })}
        </>);
};

export default App;



No comments:

Post a Comment

TODO PROJECT IN REACT JS USING ARRAY HOOK, COMPONENT AND SPREAD OPERATOR

 App.jsx import   React , {  useState  }  from   "react" ; import   TodoList   from   "./TodoList" ; const   App  = ()  ...