useMemo in React Js
App.js:
import React, {useState, useMemo} from "react";
import './App.css'
function App()
{
const [count, setCount]=useState(0)
const [item, setItem]=useState(10)
const multicountMemo=useMemo(
function multiCount()
{
console.warn("multicount")
return count*5
}, [count]
)
return(
<div className="App">
<h1>Use Memo Tutorial</h1>
<h3>Count : {count}</h3>
<h3>Item : {item}</h3>
<h3>Multicountmemo: {multicountMemo}</h3>
<button onClick={()=> setCount(count+1)}>Update Count</button>
<button onClick={()=>setItem(item*10)}>Update Item</button>
</div>
)
}
export default App;
Comments
Post a Comment