- 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 [ctime, setCtime] = useState(newT); // Array destructuring
const UpdateTime = () => {
newT = new Date().toLocaleTimeString();
setCtime(newT);
}
setInterval(UpdateTime, 1000)
return(
<>
<h1 className='top_head'> {ctime}<br/> TOP 3 NETFLIX SHOWS</h1>
{Sdata.map((val, index) => {
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