【发布时间】:2021-10-22 19:00:29
【问题描述】:
我有一个反应管理应用程序。当用户单击按钮时,用户提交的项目被批准并且项目上的参数被更改。然后使用 useCreate 挂钩在第二个数据库中创建重复记录。我需要等待 useCreate 挂钩完成,然后使用创建后的 ID 更新原始记录。我不知道该怎么做。
这里是创建一个按钮的代码,让用户批准该项目,然后进行更新,创建,需要进行后续更新。
const ApproveButton = ({ record }) => {
const [approve] = useUpdate(
"itemsubmission",
record.id,
{ status: ItemStatusTypes["APPROVED"] },
record
);
const [create] = useCreate("items", {
isValid: true,
name: record.title === null ? "" : record.title
});
const handleClick = (record) => {
approve();
const result = create();
/* This is where I need to take the results of the create function and place the
/* resulting ID in the first record's database. The update is easy, but I don't
/* know how to wait for the create to end
};
return (
<FlatButton
label={EventStatusChangeTypes["APPROVED"]}
type={"approve"}
onClick={handleClick}
/>
);
};
【问题讨论】:
标签: reactjs react-admin