【发布时间】:2022-01-12 16:21:41
【问题描述】:
错误:重新渲染过多。 React 限制了渲染的数量以防止无限循环。 我的目标是在更新国家/地区时使城市数据保持新鲜。 我收到此错误如何在此代码中修复它?
const [selectedCity, setSelectedCity] = useState({})
const [selectedCountry, setSelectedCountry] = useState({})
const [cityData,setCityData]= useState(TurkeyCityData)
function onChangeCity() {
return (val) => setSelectedCity(val)
}
function onChangeCountry() {
setCityData(`${selectedCountry.item}${'CityData'}`)
return (val)=>setSelectedCountry(val);
}
//`${selectedCountry.item}${'CityData'}`
return (
<View style={styles.container}>
<View style={styles.header}>
<SelectBox
label=''
options={countryData}
value={selectedCountry}
onChange={onChangeCountry()}
hideInputFilter={false}
width={width/2.5}
containerStyle={styles.selectbox}
arrowIconColor='#5359d1'
searchIconColor='#5359d1'
inputPlaceholder='Ülke Seç'
/>
【问题讨论】:
-
onChange={onChangeCountry} 我不这样做是因为 SelectBox 必须是 onChangeCountry()
-
我看到了问题,谢谢。
标签: javascript react-native state