Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
React Native - Can't understand the purpose of FlatList extraData prop

I understand that the FlatList extraData prop is used to re-render components when it changes.

So, imagine this example:

import React from 'react';
import { View, TouchableOpacity, Text, FlatList } from 'react-native';

export default function App() {
  const [selectedId, setSelectedId] = React.useState(null);

  const items = [
    {
      id: 'some-unique-id',
      title: 'Item 1',
    },
  ];

  const renderItem = ({ item }) => {
    return (
      <SelectableItem
        selected={selectedId === item.id}
        onPress={() => setSelectedId(item.id)}
      />
    );
  };

  return (
    <FlatList
      data={items}
      renderItem={renderItem}
      keyExtractor={(item) => item.id}
      extraData={selectedId} // works the same if I remove this
    />
  );
}

function SelectableItem({ selected, onPress }) {
  return (
    <TouchableOpacity
      style={{ backgroundColor: selected ? 'red' : 'white' }}
      onPress={onPress}>
      <Text>Click Me!</Text>
    </TouchableOpacity>
  );
}

I have implemented it thinking in re-render the component when the FlatList state changes...

Test it here.

But, the code works the same if I remove the extra data prop... why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As the document suggests

By passing extraData to FlatList we make sure FlatList will re-render itself when the state. selected changes. Without setting this prop, FlatList would not know it needs to re-render any items because it is also a PureComponent and the prop comparison will not show any changes.

I think it is because your state is changing the components are updated but in all cases, it's not possible like if you want to change the array and it doesn't affect the state the component will not be updated and the flat list will be the same. We are using an extra data prop to notify the flat list that data has been changed and it should re render.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!