const [currentPage, setCurrentPage] = useState(1);
const [rowPerPage, setRowPerPage] = useState<number>(25);
const [selectedItem, setSelectedItem] = useState<ItemProps | ''>('');
const [selectedCategory, setSelectedCategory] = useState({
cateId: '',
cateName: '',
});
.
.
.
const prevRef = useRef({
currentPage,
selectedItem,
selectedCategory,
rowPerPage,
});
useEffect(() => {
const prevValues = prevRef.current;
const checkChanged =
currentPage !== prevValues.currentPage ||
selectedItem !== prevValues.selectedItem ||
selectedCategory !== prevValues.selectedCategory ||
rowPerPage !== prevValues.rowPerPage;
if (checkChanged) {
getGoodsList(
currentPage,
selectedCategory.cateId,
selectedItem !== '' ? selectedItem.itemId : undefined,
searchText
}
prevRef.current = {
currentPage,
selectedCategory,
selectedItem,
rowPerPage,
};
}, [
currentPage,
selectedCategory,
selectedItem,
rowPerPage,
]);