Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react限制渲染的数量_Reactjs_Sweetalert - Fatal编程技术网

Reactjs react限制渲染的数量

Reactjs react限制渲染的数量,reactjs,sweetalert,Reactjs,Sweetalert,在react中,我展示产品,即 {renderPosts.map((项,索引)=>( 现在,在每个产品中,都有一个删除该产品的按钮,在我单击的一个按钮中,该按钮调用sweetAlert来删除特定的产品: <Button color="danger" simple justIcon onClick={warningWithConfirmMessage} > 一切都是这样运作的…但如果我想传递必须删除的产品ID <Button color="dange

在react中,我展示产品,即

{renderPosts.map((项,索引)=>(

现在,在每个产品中,都有一个删除该产品的按钮,在我单击的一个按钮中,该按钮调用sweetAlert来删除特定的产品:

<Button
  color="danger"
  simple
  justIcon
  onClick={warningWithConfirmMessage}
 >

一切都是这样运作的…但如果我想传递必须删除的产品ID

<Button
  color="danger"
  simple
  justIcon
  onClick={warningWithConfirmMessage(item.postId)}
 >

现在我有一个错误:

重新渲染过多。React限制渲染数量以防止无限循环

我怎么能把任何东西传给任何人


提前感谢!

您正在传递的新
onClick
处理程序每次呈现时都会调用
warningWithConfirmMessage
。要将函数作为处理程序函数传递而不是调用它,请使用:

onClick={() => warningWithConfirmMessage(item.postId)}

您正在传递的新
onClick
处理程序每次呈现时都会调用
warningWithConfirmMessage
。要将函数作为处理程序函数传递而不是调用它,请使用:

onClick={() => warningWithConfirmMessage(item.postId)}

也许你的意思是,
onClick={()=>warningwithconfirmsessage(item.postId)}
-现在它每次渲染都调用
warningwithconfirmsessage
。也许你的意思是
onClick={()=>warningwithconfirmsessage(item.postId)}
-现在它每次渲染都调用
warningwithconfirmsessage