I'm looking to display a list of elements and let the user select some elements from this list. How can I make the selected items (from selectedIds) go in the beginning of that list. Can we use transformResponse for that? Or should it be done in the component?
Here is the call using redux-toolkit
export const exApi = api.injectEndpoints({
endpoints: (builder) => ({
getEx: builder.query({
query: ({ type }) => `/exemple?type=${type}`,
transformResponse: (response: { results }) => response.results,
}),
}),
});
export const { useGetExQuery } = exApi;
And here is the component
const { selectedIds } = props;
const { data: results } = useGetExQuery({ type: "tags" });
return (
<FlatList
data={results}
renderItem={({ item }) => (
<DisplayElement
key={item.id}
item={item}
isSelected={selectedIds?.includes(item.id)}
onPress={() => onPress(item.id)}
/>
)}
/>
);