New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-fetch-list

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-fetch-list

This component will manage data loading, rereshing and loading more with a fetch prop which returns a promise. You don't need to do these by youself. Rendering with Flatlist.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

React Native Fetch List

This component will manage data loading, rereshing and loading more with a fetch prop which returns a promise. You don't need to do these by youself. Rendering with Flatlist.

Usage

props

Other props will be spread onto FlatList

NameTypedescription
fetch(params: { page: number; limit: number }) => Promise<T[]>how to get data
limitnumber, optionaldata limit per page, default 10
dataT[], optionalif you want to manage the data by yourself, use this prop
onChange(data: T[]) => void, optionalbe triggered when data change
filter(item: T) => boolean, optionalmethod to filter some data

example

import React, { useRef, useEffect } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import ListView from 'react-native-fetch-list';

const App = () => {
  const keyExtractor = item => item.id;

  const request = ({ page, limit }) => {
    return fetch(
      `https://cnodejs.org/api/v1/topics?page=${page}&limit=${limit}`,
    )
      .then(res => res.json())
      .then(data => data.data);
  };

  const list = useRef();

  useEffect(() => {
    list.current.fetch();
  }, []);

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

  return (
    <ListView
      ref={list}
      fetch={request}
      keyExtractor={keyExtractor}
      renderItem={renderItem}
      ListEmptyComponent={<Text>no data</Text>}
    />
  );
};

const styles = StyleSheet.create({
  item: {
    paddingVertical: 10,
    paddingHorizontal: 15,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderBottomColor: '#999',
  },
});

export default App;

Keywords

react-native

FAQs

Package last updated on 16 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts