Last active
April 12, 2020 14:35
-
-
Save pubudu-pagero/7e8e13632627c459bb9f1f66fb516493 to your computer and use it in GitHub Desktop.
React-memo example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useMemo, useState } from "react"; | |
const ComponentA = () => { | |
const [{count,name}, setValues] = useState({count: 0, name: "test"}) | |
setInterval(() => { | |
setValues(currentValues => ({ | |
...currentValues, | |
count: currentValues.count + 1 | |
})) | |
},10000) | |
return ( | |
<div> | |
<ComponentB count={count}></ComponentB> | |
<ComponentC name={name}></ComponentC> | |
</div> | |
) | |
} | |
const ComponentB = ({ count }) => { | |
console.log("Component B is rendered :" + count) | |
return <h1>Hello , {count}</h1>; | |
} | |
const ComponentC = ({ name }) => { | |
console.log("Component C is rendered :" + name) | |
return <h1>Hello , {name}</h1>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment