gpt4 book ai didi

reactjs - 当用户选择一个选项但随后将其更改为另一个选项时,React 崩溃而不显示错误

转载 作者:行者123 更新时间:2023-12-02 07:28:50 30 4
gpt4 key购买 nike

当用户选择任何选项时,我的代码正在工作。
但是,当他们选择“现在”选项,然后改变主意并选择“特定”选项时,React 崩溃而不显示错误 - 它只是显示一个白屏。
This problem doesn't occur when the options are selected the other way round - when 'specific' is selected and the user changes their mind and selects 'now'.
When 'specific' is selected a new input is rendered.
代码的简化版本如下:

render() {

let startSelling = values.tickets.map((e,i) => {
if(e.startSelling == 'specific'){
return(
<div>
<DatePicker
className="datePicker"
timeIntervals={15}
onChange={event => this.props.setSpecificTime(event, i, 'startSellingTime', values)}
selected={values.tickets[i].startSellingTime}
placeholderText='Select Date And Time'
showTimeSelect
dateFormat="Pp"
/>
</div>
)
}else{return <div></div>}
})


return (
<>

{this.state.tickets.map((e, i) => {
return (
<div>
<div>
<select
value={values.tickets[i].startSelling}
onChange={event => this.props.changeSellingTimes(event, i, 'startSelling', 'startSellingTime', values)}
>
<option value='' disabled>Start Selling Tickets</option>
<option value="now">Now</option>
<option value="specific">Specific Date and Time</option>
{i===1 ? <option value="whenPreviousSoldOut">When {values.tickets[0].ticketType} Is Sold Out</option>:<option value="whenPreviousSoldOut" disabled={i==0}>When A Previous Ticket Is Sold Out</option>}
</select>
</div>
{startSelling[i]}
</div>
)

})}

</>

)
}
我哪里错了?

最佳答案

找到了。选择“现在”将日期保存为状态中的时刻对象。 Datepicker 在尝试读取它时导致 react 崩溃。

关于reactjs - 当用户选择一个选项但随后将其更改为另一个选项时,React 崩溃而不显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63530696/

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