我有一个由componentDidMount和React Hooks混合而成的项目(很糟糕,我知道),但是在componentDidMount的I setState之一中,允许contractData匹配ID的参数,如下所示
componentDidMount = async() => {
let tasks = [];
try {
tasks = await getTasks(this.props.match.params.id);
}
catch (err) {
if (err !== HttpStatus.NOT_FOUND) {
throw err;
}
}
this.setState({ contract: await getContractData(this.props.match.params.id), tasks: tasks });
}
除了在useEffect中获取getSupplierData之外,我还需要对参数做类似的事情
const [suppliers, setSupplierList] = useState([]);
useEffect(() => {
getSupplierData().then(response => {
setSupplierList(response);
});
}, []);
我该怎么办?