本人后端兼职前端,新人,对react的一些核心概念似懂非懂...
问题: 点开弹出框,显示的用户头像是上一次的,fileList不是最新值,除了把Modal放在return中之外请问还能如何解决?
伪代码如下:
const comp = () => {
const [fileList,setFileList] = useState(UploadFile[]);
// 点击按钮,触发
const showModal = (userId: number) => {
loadData(userId)
Modal.open(
..
children: getForm() // 调用getForm获取表单
handleOkay: ...
handleCancel: ...
)
}
async function loadData (userId: number) {
axios.get(..) // 调后端,查用户信息.
.then(url => {
setFileList({ // 放进state中
..
url
})
})
}
cosnt getForm = () => {
props = {
..
defaultList = fileList // 取state变量
}
return (
<Form>
<Upload props={..props} >上传</>
</Form>
)
}
return (
<Button onClick={() => showModal(1)}>XXXX</Button>
)
}
export default comp;