Skip to content

Commit e71791b

Browse files
committed
card list hooks
1 parent f9c2117 commit e71791b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Cards/CardList.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ function calcWidth() {
2020
}
2121

2222
function CardList(props) {
23-
const [grid, setGrid] = React.useState(null)
24-
gridRedraw()
25-
function gridRedraw(delay = 10) {
26-
setTimeout(() => { if (grid && grid.updateLayout) grid.updateLayout() }, delay)
23+
const grid = React.useRef(null)
24+
React.useEffect(gridRedraw, [props.size])
25+
26+
function gridRedraw() {
27+
setTimeout(() => { if (grid.current && grid.current.updateLayout) grid.current.updateLayout() }, 10)
2728
}
2829

2930
const gridSettings = {
30-
gridRef: setGrid,
31+
ref: grid,
3132
columnWidth: calcWidth(),
3233
gutterWidth: 0,
3334
gutterHeight: 0,

0 commit comments

Comments
 (0)