Skip to content

Using React Hooks initialize Data, But Not Work Correctly #26059

Description

@LiuL0703

here is my code

importReact,{Fragment,useState,useEffect,useReducer}from'react';import{SafeAreaView,ScrollView,View,Text,TouchableHighlight,FlatList}from'react-native';constHomePage=(props)=>{const[selectedName,setselectedName]=useState('');const[nameList,setNameList]=useState([{'name':'abcd'},{'name':'abcd'},{'name':'abcd'},{'name':'abcd'}]);functionhandleSelectName(value){setselectedName(value);}return(<Fragment><SafeAreaView><ScrollViewcontentInsetAdjustmentBehavior="automatic"><View>{nameList.length>0&&CustomCount(nameList,selectedName,handleSelectName)}</View></ScrollView></SafeAreaView></Fragment>);};functionCustomCount(data,count,handle){constcounterStyle={fontSize: 30,color: 'red',};return(<FlatListdata={data}renderItem={({ item, index })=>(<Viewkey={item}><TouchableHighlightonPress={()=>handle(index)}><Textstyle={index===count ? counterStyle : {color: 'green'}}>{item.name}</Text></TouchableHighlight></View>)}numColumns={3}/>)}exportdefaultHomePage;

What I expected

when i clicked the name, which name's style changes

What actually did

nothing happened

env

"react": "16.8.6",
"react-native": "0.60.4",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.Type: QuestionIssues that are actually questions and not bug reports.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions