I want to update my TaskDetail
(at Right Side) component with new card
data but when I change the value of card from handleCardClick
callback it does not reflect the change to that specific component. If you look at attached gif you will see that useEffect
is getting the updated values of card
and the page
variable in the same call back showing updated value on view.
Here is the minimum code that depict my problem.
const [selectedCard, setSelectCard] = useState(null);
const [selectedColumn, setSelectedColumn] = useState(null);
// Page Updater
const [page, setPage] = useState(0);
const handleCardClick = (e, card, columnId) => {
setSelectedColumn(columnId);
setSelectCard(card);
setPage(page + 1);
}
useEffect(() => {
// action on update of movies
console.log(selectedCard);
console.log(selectedColumn);
}, [selectedCard]);
return (
<Container>
<DragDropContext onDragEnd={handleDragEnd}>
{boardData.map((list) => (
<List key={list.title} column={list} handleAddTask={handleAddTask} handleCardClick={handleCardClick} />
))}
</DragDropContext>
<p>{page}</p>
<> {(page !== 0) && <TaskDetail card={selectedCard} columnId={selectedColumn} />}</>
</Container>
);
This is the most relevant to my question The useState set method is not reflecting a change immediately but I did't find the solution from it.