“Flatlist React Native” Code-Antworten

Flatlist Onrefresh React Native

const [isFetching, setIsFetching] = useState(false);

const fetchData = () => {
  dispatch(getAllTopicAction(userParamData));
  setIsFetching(false);
};

const onRefresh = () => {
  setIsFetching(true);
  fetchData();
};

<FlatList
  data={topics}
  keyExtractor={(item) => item.id.toString()}
  renderItem={renderItem}
  onRefresh={onRefresh}
  refreshing={isFetching}
  progressViewOffset={100}
  ListEmptyComponent={<Empty message="No data found." />}
/>;
Dayanaohhnana

So verwenden Sie Flatlist KeyExtractor

<FlatList 
  data={[{name: 'a'}, {name: 'b'}]} 
  renderItem={
    ({item}) => <Text>{item.name}</Text>
  } 
  keyExtractor={(item, index) => index.toString()}
/>
Excited Eland

Flatlist React Native

import React from 'react';
import { SafeAreaView, View, FlatList, StyleSheet, Text, StatusBar } from 'react-native';

const DATA = [
  {
    id: 'bd7acbea-c1b1-46c2-aed5-3ad53abb28ba',
    title: 'First Item',
  },
  {
    id: '3ac68afc-c605-48d3-a4f8-fbd91aa97f63',
    title: 'Second Item',
  },
  {
    id: '58694a0f-3da1-471f-bd96-145571e29d72',
    title: 'Third Item',
  },
];

const Item = ({ title }) => (
  <View style={styles.item}>
    <Text style={styles.title}>{title}</Text>
  </View>
);

const App = () => {
  const renderItem = ({ item }) => (
    <Item title={item.title} />
  );

  return (
    <SafeAreaView style={styles.container}>
      <FlatList
        data={DATA}
        renderItem={renderItem}
        keyExtractor={item => item.id}
      />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: StatusBar.currentHeight || 0,
  },
  item: {
    backgroundColor: '#f9c2ff',
    padding: 20,
    marginVertical: 8,
    marginHorizontal: 16,
  },
  title: {
    fontSize: 32,
  },
});

export default App;
Dayanaohhnana

Reagieren Sie die native flache Liste

import { FlatList } from 'react-native'

...

<FlatList
  data={items}
  renderItem={
    ({ item, index, separators }) => <Component item={item} />
  }
  keyExtractor={item => item.id}
/>
florinrelea

Flatlist Onrefresh React Native

const [isFetching, setIsFetching] = useState(false);

const fetchData = () => {
  dispatch(getAllDataAction(userParamData));
  setIsFetching(false);
};

const onRefresh = () => {
  setIsFetching(true);
  fetchData();
};

<FlatList
  data={topics}
  keyExtractor={(item) => item.id.toString()}
  renderItem={renderItem}
  onRefresh={onRefresh}
  refreshing={isFetching}
  progressViewOffset={100}
  ListEmptyComponent={<Empty message="No data found." />}
/>;
Dayanaohhnana

Flatlist reagieren native horizontale

<FlatList
    data={this.state.newsFeed}
    refreshing={this.state.refreshing}
    horizontal={this.state.isHorizontal}
    ref={ref => { this.newsFeedListRef = ref; }}
    renderItem={this.renderNewsFeedRow.bind(this)}
    keyExtractor={(item, index) => `feed_${index}`}
    onRefresh={this.__handleNewsFeedOnRefresh.bind(this)}
    //renderScrollComponent={this.renderScrollComponent.bind(this)}
    ListHeaderComponent={this.renderListHeaderComponent.bind(this)}
    getItemLayout={(data, index) => ({ index, length: ITEM_HEIGHT, offset: (ITEM_HEIGHT * index) })} />
Troubled Tortoise

Ähnliche Antworten wie “Flatlist React Native”

Fragen ähnlich wie “Flatlist React Native”

Weitere verwandte Antworten zu “Flatlist React Native” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen