我創建了一個功能組件
import React from 'react';
import { View, ScrollView, Text, SafeAreaView } from 'react-native';
import { useState, useEffect } from 'react';
const listFiliere = ({item}) => {
const [show, setShow] = useState(false);
return(
<View style={{ height: 30, flex: 1, justifyContent: 'center', borderBottomWidth: 1, borderBottomColor: 'blue' }}>
<Text>{ item.name }</Text>
</View>
);
}
export default listFiliere
我在平面串列的 renderItem 類組件中呼叫了這個;并回傳 invlide 鉤子呼叫錯誤;將其稱為原因的類組件是原因還是其他?
uj5u.com熱心網友回復:
可能是幾件事。您發布的代碼并不多。看看這個頁面。您可以檢查的幾件事
uj5u.com熱心網友回復:
如果問題是您在類組件中呼叫 useState,請參考這篇文章。
基本上,您不能在類組件中使用 useState 掛鉤。等效的類組件是:
export class ListFiliere extends React.Component {
constructor(props) {
super(props);
this.state = {
show: false
};
}
render() {
return(
<View style={{ height: 30, flex: 1, justifyContent: 'center', borderBottomWidth: 1, borderBottomColor: 'blue' }}>
<Text>{ item.name }</Text>
</View>
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/411766.html
標籤:
