Answer the question
In order to leave comments, you need to log in
Why is the component not being redrawn?
Good evening! We need to do pagination, for this I send a network request: axios.get(`/numbers/${props.numbersPage.currentPage}`), I store the current page in the redux store. To emulate pagination, I created an array page, this array was mapped, in the body of the cycle I create spans, by clicking on the span I change the state currentPage
, but the page is not redrawn, why?
Request axios code:
useEffect(() => {
axios.get(`/post/${props.numbersPage.currentPage}`)
.then(res => {
res.data.forEach(item => {
props.addPost(item.id);
});
}, []);
<div className="page">
{pages.map((page, index) => <span
onClick={() => dispatch(setCurrentPageAC(page))}
key={index}>{page}
</span>)}
</div>
case SET_CURRENT_PAGE: {
return {
...state,
currentPage: action.payload
}
}
Answer the question
In order to leave comments, you need to log in
You store and change the page in the redux store, but the next one doesn’t care what you have there, it won’t know about these changes.
For routing in next js, there are the following ways:
1 - router.push
2 - next / link
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question