在 React 中使用 SweetAlert 2 的组件作为 html

问题描述 投票:0回答:1

如何在带有 SweetAlert2 的 ReactJs 中使用组件作为 html body?我在点击事件上调用

swal

swal({
  title: "Title",
  html: <SomeComponent onChange={this.handleChange}/>
});

我无法使用

ReactDOM.render(<SomeComponent onChange={this.handleChange}/>)
,因为我必须在
handleChange()
事件上致电
onChange

reactjs sweetalert sweetalert2
1个回答
0
投票

你可以使用:

const modalComponent = document.createElement("div");
ReactDOM.render(<YouComponent />, modalComponent )

swal({
html: modalComponent 
})
© www.soinside.com 2019 - 2024. All rights reserved.