Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LiuL0703 opened this issue Aug 14, 2019 · 1 comment
Closed

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

LiuL0703 opened this issue Aug 14, 2019 · 1 comment
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.

Comments

@LiuL0703
Copy link

here is my code

import React, {Fragment,useState, useEffect,useReducer} from 'react';
import {
  SafeAreaView,
  ScrollView,
  View,
  Text,
  TouchableHighlight,
  FlatList
} from 'react-native';


const HomePage = (props) => {
  const [selectedName,setselectedName] = useState('');
  const [nameList, setNameList] = useState([{'name':'abcd'},
      {'name':'abcd'},
      {'name':'abcd'},
      {'name':'abcd'}
  ]);

  function handleSelectName(value){
    setselectedName(value);
  }


  return (
    <Fragment>
      <SafeAreaView>
        <ScrollView
          contentInsetAdjustmentBehavior="automatic">
          <View>
            { nameList.length > 0 && CustomCount(nameList,selectedName,handleSelectName) }
          </View>
        </ScrollView>
      </SafeAreaView>
    </Fragment>
  );
};


function CustomCount(data,count,handle){
  const counterStyle = {
    fontSize: 30,
    color: 'red',
  };
  return (
    <FlatList
      data={data}
      renderItem={({ item, index }) => (
        <View key={item}>
          <TouchableHighlight 
            onPress={()=>handle(index)} 
          >
            <Text style={ index === count ? counterStyle : {color: 'green'}} >{item.name}</Text>
          </TouchableHighlight>
        </View>
      )}
      numColumns={3}
    />
  )
}

export default HomePage;

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",

@LiuL0703 LiuL0703 added the Type: Question Issues that are actually questions and not bug reports. label Aug 14, 2019
@react-native-bot
Copy link
Collaborator

We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

👉 Click here if you want to report a reproducible bug or regression in React Native.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: No Template labels Aug 14, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Oct 4, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.
Projects
None yet
Development

No branches or pull requests

2 participants