Reactjs 错误:重新渲染过多。React限制渲染的数量以防止无限循环React Native 函数保留屏幕({navigation}){ const[switchValue,setSwitch]=使用状态(false); const[loading,isLoading]=useState(true); const[data]=useState([data]); 返回( 米拉多酒店 {getCurrentDate()} 设置开关(正确)} 值={switchValue} /> 萨拉 撕裂 {正在加载(真)(
将其视为一个无限循环。您的dom被无限地呈现。您的代码中有一些东西在一次又一次地设置状态 我认为错误就在这条语句中,因为您一次又一次地将状态重置为true,从而导致无限循环:Reactjs 错误:重新渲染过多。React限制渲染的数量以防止无限循环React Native 函数保留屏幕({navigation}){ const[switchValue,setSwitch]=使用状态(false); const[loading,isLoading]=useState(true); const[data]=useState([data]); 返回( 米拉多酒店 {getCurrentDate()} 设置开关(正确)} 值={switchValue} /> 萨拉 撕裂 {正在加载(真)( ,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,将其视为一个无限循环。您的dom被无限地呈现。您的代码中有一些东西在一次又一次地设置状态 我认为错误就在这条语句中,因为您一次又一次地将状态重置为true,从而导致无限循环: function ReservationScreens({ navigation }) { const [switchValue, setSwitch] = useState(false); const [loading, isLoading] = useState(true); const [data] =
function ReservationScreens({ navigation }) {
const [switchValue, setSwitch] = useState(false);
const [loading, isLoading] = useState(true);
const [data] = useState([data]);
return (
<SafeAreaView
style={{
flex: 1,
paddingTop: Platform.OS === "android" ? 30 : 0,
}}
>
<View style={styles.top}>
<Text style={styles.text_picker}>El Mirador</Text>
<View></View>
<View style={styles.top_buttons}>
<TouchableOpacity>
<Feather name="calendar" size={25} />
</TouchableOpacity>
<TouchableOpacity style={{ marginLeft: 25 }} >
<Feather name="settings" size={25} />
</TouchableOpacity>
</View>
</View>
<View style={styles.subTop}>
<Text style={styles.date_text}>{getCurrentDate()}</Text>
<Switch
style={styles.switcher}
onValueChange={() => setSwitch(true)}
value={switchValue}
/>
</View>
<View style={styles.midTop}>
<Text>Sala</Text>
<Text>Torn</Text>
</View>
<View style={{}}>
{isLoading(true) ? (
<ActivityIndicator style={{ marginTop: 100 }} size="large" />
) : (
<FlatList
data={data}
style={{ marginTop: 10, borderRadius: 25 }}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => (
<View style={styles.books}>
<View>
<Text style={styles.book_hour_text}>Hora de reserva</Text>
<Text style={styles.name_text}>{item.name}</Text>
</View>
<View style={{ marginStart: 15 }}>
<Text style={styles.phone_text}>{item.telephone}</Text>
<Text
style={{
fontSize: 14,
marginStart: 10,
color: "#393b44",
}}
>
{item.num_people} personas
</Text>
</View>
<TouchableOpacity style={{ marginTop: 20, marginStart: 15 }}>
<Feather name="chevron-down" size={25} />
</TouchableOpacity>
<View
style={{
borderWidth: 0.2,
flex: 1,
marginTop: 20,
marginBottom: 20,
marginEnd: 5,
}}
></View>
</View>
)}
/>
)}
</View>
</SafeAreaView>
);
}
把这个也换一下
isLoading(true) ? (
或
将其视为一个无限循环。您的dom被无限地呈现。您的代码中有一些东西在一次又一次地设置状态 我认为错误就在这条语句中,因为您一次又一次地将状态重置为true,从而导致无限循环:
function ReservationScreens({ navigation }) {
const [switchValue, setSwitch] = useState(false);
const [loading, isLoading] = useState(true);
const [data] = useState([data]);
return (
<SafeAreaView
style={{
flex: 1,
paddingTop: Platform.OS === "android" ? 30 : 0,
}}
>
<View style={styles.top}>
<Text style={styles.text_picker}>El Mirador</Text>
<View></View>
<View style={styles.top_buttons}>
<TouchableOpacity>
<Feather name="calendar" size={25} />
</TouchableOpacity>
<TouchableOpacity style={{ marginLeft: 25 }} >
<Feather name="settings" size={25} />
</TouchableOpacity>
</View>
</View>
<View style={styles.subTop}>
<Text style={styles.date_text}>{getCurrentDate()}</Text>
<Switch
style={styles.switcher}
onValueChange={() => setSwitch(true)}
value={switchValue}
/>
</View>
<View style={styles.midTop}>
<Text>Sala</Text>
<Text>Torn</Text>
</View>
<View style={{}}>
{isLoading(true) ? (
<ActivityIndicator style={{ marginTop: 100 }} size="large" />
) : (
<FlatList
data={data}
style={{ marginTop: 10, borderRadius: 25 }}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => (
<View style={styles.books}>
<View>
<Text style={styles.book_hour_text}>Hora de reserva</Text>
<Text style={styles.name_text}>{item.name}</Text>
</View>
<View style={{ marginStart: 15 }}>
<Text style={styles.phone_text}>{item.telephone}</Text>
<Text
style={{
fontSize: 14,
marginStart: 10,
color: "#393b44",
}}
>
{item.num_people} personas
</Text>
</View>
<TouchableOpacity style={{ marginTop: 20, marginStart: 15 }}>
<Feather name="chevron-down" size={25} />
</TouchableOpacity>
<View
style={{
borderWidth: 0.2,
flex: 1,
marginTop: 20,
marginBottom: 20,
marginEnd: 5,
}}
></View>
</View>
)}
/>
)}
</View>
</SafeAreaView>
);
}
把这个也换一下
isLoading(true) ? (
或