gpt4 book ai didi

reactjs - 如何通过 ReactJS 中的链接传递多个状态

转载 作者:行者123 更新时间:2023-12-04 18:38:34 24 4
gpt4 key购买 nike

我想为我的下一页传递多个状态,我正在从另一个页面重定向。

一个我已经通过了,而且工作正常。

<Link to ={{pathname: "/CreateEventUser", state: { bucket_id: !this.state.selected_bucket.id ? this.state.recent_bucket : this.state.selected_bucket } }} >
<button type="button" className="btn btn-danger">Create an Event</button>
</Link>

现在我必须通过两个状态。它的语法是什么?
<Link to ={{pathname: "/EventDetailsUser", state: { bucket_id: !this.state.selected_bucket.id ? this.state.recent_bucket : this.state.selected_bucket, eventId: event.id}}} >

最佳答案

state位置路径名中的参数除外和对象,因此您可以根据需要传递尽可能多的值,方法是将 then 作为对象传递,例如

<Link to ={{
pathname: "/CreateEventUser",
state: {
bucket_id: !this.state.selected_bucket.id ? this.state.recent_bucket : this.state.selected_bucket,
new_id: this.state.newID,
anotherValue: this.state.anotherValue
}
}} >
<button type="button" className="btn btn-danger">Create an Event</button>
</Link>

关于reactjs - 如何通过 ReactJS 中的链接传递多个状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47484406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com