Closed webface closed 4 years ago
SOLVED
let flipPage = useRef(null);
const next =()=>{flipPage.gotoNextPage()}
const prev =()=>{flipPage.gotoPreviousPage()}
.....
<span>
<IconButton aria-label="prev" className={classes.margin} size="small" onClick={prev}>
<ArrowBackIcon fontSize="inherit" />
</IconButton>
<IconButton aria-label="next" className={classes.margin} size="small" onClick={next}>
<ArrowForwardIcon fontSize="inherit" />
</IconButton>
</span>
I'm glad you could figure this out! In case you were wondering what happened:
onClick
handler was called immediately, and the ref
was still null
.onClick
. Except this is called after the ref was set. Therefore you could also have written:<IconButton aria-label="prev" className={classes.margin} size="small" onClick={() => flipPage.gotoNextPage()}>
<ArrowBackIcon fontSize="inherit" />
</IconButton>
I'm using nextjs and material ui. When I try to useRef I get an error
Here is my code