I am working on a screen that can display up to 1000 data retrieved from the API.
Here is the image:
https://i.sstatic.net/ErbDD.png
Now, I have implemented a drop-down box where users can select alphabetically from A to Z. After selecting an alphabetical order, the data will be arranged accordingly. How can I achieve this functionality in my code?
I have tried the following code snippet:
// setData(json.results); <==================it for sorting
// setData((prevData) => [...prevData, ...newData]);
// const sorted = [...sortedData, ...newData].sort((a, b) => {
// const lastNameA = a.name.first.toLowerCase();
// const lastNameB = b.name.first.toLowerCase();
// if (lastNameA < lastNameB) return -1;
// if (lastNameA > lastNameB) return 1;
// return 0;
// });
// setSortedData(sorted);
However, it is not functioning as expected when I select the A to Z list in the drop-down box.
Can someone guide me on how to achieve this successfully?
Code:
import {
StyleSheet,
Text,
View,
Image,
TextInput,
FlatList,
ActivityIndicator,
SafeAreaView,
} from 'react-native';
import React, { useEffect, useState } from 'react';
import { scale, verticalScale, moderateScale } from 'react-native-size-matters';
import { RFPercentage } from 'react-native-responsive-fontsize';
import SelectDropdown from 'react-native-select-dropdown';
const sortby = ['A to Z', 'Newest', 'Oldest'];
const App = () => {
// rest of the code...
};
export default App;
// rest of the styles and components...