Skip to content

Instantly share code, notes, and snippets.

@pubudu-pagero
Last active April 12, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pubudu-pagero/7e8e13632627c459bb9f1f66fb516493 to your computer and use it in GitHub Desktop.
Save pubudu-pagero/7e8e13632627c459bb9f1f66fb516493 to your computer and use it in GitHub Desktop.
React-memo example code
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