Skip to content

Instantly share code, notes, and snippets.

@shrimpy
shrimpy / great.js
Created December 10, 2020 22:29
Reactjs: useCallback and React.memo fun - code - 4
let _int_val = 0;
const IntValComp = React.memo(({initFunc}) => {
const [value, setValue] = React.useState(-1);
console.log('IntValComp');
React.useEffect(
() => {
const val = _int_val++;
if (_int_val >= 100000) _int_val = 0;
@shrimpy
shrimpy / ok.js
Created December 10, 2020 22:28
Reactjs: useCallback and React.memo fun - code - 3
let _int_val1 = 0;
const IntValComp1 = ({initFunc}) => {
const [value, setValue] = React.useState(-1);
console.log('IntValComp1');
React.useEffect(
() => {
const val = _int_val1++;
if (_int_val1 >= 100000) _int_val1 = 0;
@shrimpy
shrimpy / loop.js
Created December 10, 2020 22:26
Reactjs: useCallback and React.memo fun - code - 2
let _int_val2 = 0;
const IntValComp2 = ({initFunc}) => {
const [value, setValue] = React.useState(-1);
React.useEffect(
() => {
const val = _int_val2++;
if (_int_val2 >= 100000) _int_val2 = 0;
@shrimpy
shrimpy / sample.js
Created December 10, 2020 22:23
Reactjs: useCallback and React.memo fun - code - 1
let _int_val = 0;
const IntValComp = React.memo(({initFunc}) => {
const [value, setValue] = React.useState(-1);
// expect to init value once only
React.useEffect(
() => {
const val = _int_val++;
if (_int_val >= 100000) _int_val = 0;