我有一个平面列表,它呈现从数据库获取的数据,所以我确保项目按类型排序。
\n\n现在我想在每个部分的顶部渲染一个文本,以区分每个部分,标题类型(例如:专业:然后是专业的部分,医生:然后是医生的部分)\n这里是看看我的代码:
\n<FlatList\n data={this.state.data.sort((a, b) => a.type === \'sp\xc3\xa9cialit\xc3\xa9\' ? -1 : 1)}\n keyExtractor={item => { return item.id }}\n renderItem={({ item }) => \n <TouchableOpacity onPress={() =>NavigationService.navigate(\'O\xc3\xb9 ?\',{lien: item.lien, choix: c}) }> \n {item.type == \'sp\xc3\xa9cialit\xc3\xa9\' && (\n \n <Highlighter\n highlightStyle={{ backgroundColor: \'#FFC617\' }}\n searchWords={[this.searchedText]}\n textToHighlight={item.name}\n style={{paddingLeft:10,color: \'#2c3e50\',height:42,backgroundColor: \'white\'}}\n />\n \n )}\n {item.type == \'Tag\' && (\n <Highlighter\n highlightStyle={{ backgroundColor: \'#FFC617\' }}\n searchWords={[this.searchedText]}\n textToHighlight={item.name}\n style={{paddingLeft:10,color: \'#2c3e50\',height:42,backgroundColor: \'white\'}}\n />\n \n )}\n {item.type == \'M\xc3\xa9decin\' && (\n <View style={{ …
Run Code Online (Sandbox Code Playgroud) 因此,在获取数据并尝试将其分配给我的 const 后,我收到此错误。我第一次使用钩子,我不知道我做错了什么。这是我的代码:
export default function MedProfilScreen({route}){
//const {id,name,specialite,work}=route.params;
const [data,setData]=useState([])
useEffect(()=>{
fetch('http:......)
.then((response) => response.json())
.then((res) => {
setData(data.res);
console.log(res)
})
.done();
});
Run Code Online (Sandbox Code Playgroud)
这就是 console.log 显示的内容:
Array [
Object {
"code": "12459552",
"id": 7,
"name": "Dr xavier vilan",
"speciality": "Cardio",
},
Object {
"education": Array [
Object {
"date_debut": "2020-02-07",
"date_end": "2020-02-06",
"diplome": "asmaa",
"school": "asmaa",
"city": "vullez",
},
]}
]
Run Code Online (Sandbox Code Playgroud)