Skip to content

Commit 5a00dd4

Browse files
committed
refactor lastPageLen to ref
1 parent 8b89e77 commit 5a00dd4

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎src/components/VariableList.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useMemo, useState} from 'react';
1+
import React, {useMemo, useRef} from 'react';
22
import * as Tools from '../utils/Tools';
33
import VariableItem from './VariableItem';
44

@@ -7,7 +7,7 @@ const notFoundImg = '//user-images.githubusercontent.com/799578/50722775-1a9a1d0
77
const animationName = Math.random() > 0.5 ? 'zoomInDown' : 'zoomInUp';
88

99
export default function VariableList(props) {
10-
const [lastPageLen, setLastPageLen] = useState(0);
10+
const lastPageLen = useRef();
1111
const list = useMemo(() => { // same as "shouldComponentUpdate", only compute when "variableList" has changed
1212
const variableList = props.variableList;
1313
const pageLen = variableList.length;
@@ -16,7 +16,7 @@ export default function VariableList(props) {
1616
pages.push(<img style={{maxWidth: '100%'}} src={notFoundImg}/>);
1717
}
1818
variableList.forEach((list, i) => {
19-
const isLast = i === pageLen - 1 && lastPageLen != pageLen;
19+
const isLast = i === pageLen - 1 && lastPageLen.current != pageLen;
2020
const variables = list.map((variable, j) => {
2121
let style = {}, className = '', duration = (list.length - j) / list.length;
2222
if (isLast) {
@@ -37,7 +37,7 @@ export default function VariableList(props) {
3737
Array.prototype.unshift.apply(pages, variables)
3838
}
3939
});
40-
setLastPageLen(pageLen);
40+
lastPageLen.current = pageLen;
4141
return pages;
4242
}, [props.variableList]);
4343

0 commit comments

Comments
 (0)