0

export default class Send extends Component{
    constructor(props)
    {
    
      super(props);
      const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
      this.state = { 
        userDataSource: ds,
      isLoading: true,
    
      PickerValueHolder : '',
      amount:'',
 RxAmount:'',
 exchange:'',
 input1:'',
 recRate:[{},{},{}]
 
     }
    }
    
    fetchUsers(){
        fetch('https://trs.php?some parameters')
            .then((response) => response.json())
            .then((response) => {
             console.log(response)
                this.setState({
                    userDataSource: this.state.userDataSource.cloneWithRows(response),
                    
                });
            });
    }
       renderRow(user , sectionId, rowId, highlightRow,key){
           
                return(
                <View style={styles.row}>
                        <Text style={styles.rowText}> Rate {user[0].Rate}</Text>
                    </View>
                
                ); }
 <ListView 
    dataSource={this.state.userDataSource}
    renderRow={this.renderRow.bind(this)}
/>

i want to access the rate highlighted in yellow

I am new to react native so i want to access an array of objects and get only one particular value which is highlighted in yellow and i don't know how i can do it ?

Thanks

1 Answer 1

3

ListView is deprecated and it is encouraged that you use FlatList instead. One reason of which is because of its "easier to use API"

Provided that your userDataSource object looks like this:

[
 {MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
 {MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
 {MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"}
]

Your renderItem function (instead of renderRow) should look like this:

renderItem({item}){
  return(
      <View style={styles.row}>
          <Text style={styles.rowText}> Rate {item.Rate}</Text>
      </View>
  );
}

And you can create your list like this:

<FlatList
    data=this.state.userDataSource
    renderItem={({item}) => this.renderItem(item)}
/>
Sign up to request clarification or add additional context in comments.

3 Comments

i add a snippet code can you show how can i implement your answer
Thanks for your answer ,but it's getting me an error undefined is not an object "item.Rate"
To debug what the item object is, you can use alert(item); inside of you renderItem function. This will print out all of your items. (You might have to use alert(JSON.stringify(item))). That will tell you what the item object is made up of so you can see why it's Rate is undefined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.