简体   繁体   English

如何将参数传递给 onSuccess function?

[英]How to pass parms to onSuccess function?

On react-admin I have an Edit element and want to to invoke a function on success.在 react-admin 上,我有一个 Edit 元素,想在成功时调用 function。

 <Edit onSuccess= {onSuccess } {...props}>
// properties
</Edit>

The onSuccess function (on typescript): onSuccess function(在打字稿上):

   const onSuccess = () => {
   redirect(`/XXX/${id}`);
   refresh();
   }

My question is how to pass the id of the edited element?我的问题是如何传递已编辑元素的 id?

Thank you!谢谢!

<Edit onSuccess={() => onSuccess(id)} {...props}> // passing the ID
// properties
</Edit>
const onSuccess = (id) => { // reading the ID
   redirect(`/XXX/${id}`);
   refresh();
   }
<Edit onSuccess= {(id) => onSuccess } {...props}>
// properties
</Edit>

const onSuccess = (id) => { redirect( /XXX/${id} ); const onSuccess = (id) => { redirect( /XXX/${id} ); refresh();刷新(); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM