我需要从length
获取列表的API
并将其显示为计数器。
但是加载后,它又回到了原始状态。
let dataAll = []; //Global variable
const [isLoading, setIsLoading] = useState(false);
const [isAll, setIsAll] = useState(dataAll);
const [state, setState] = useState({
allCounter: 0,
loading: true,
});
const fetchAll = async (params = {}) => {
try {
dataAll = await TriggerRequestAPI.getAllTickets();
const counter = dataAll.length;
setIsLoading(false);
setIsAll(dataAll);
setState({
state,
loading: false,
allCounter: counter,
params
});
}
catch (err) {
setIsLoading(true);
console.log(err);
message.error(`There is a problem in listing all table`, 3);
}
};
useEffect(() => {
setIsLoading(true);
fetchAll();
}, []);