npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-fresh-flatlist

v0.8.5

Published

fresh fresh fresh list!

Downloads

44

Readme

react-native-fresh-flatlist

Do you need to update FlatList data frequently? Are people constantly complaining that they don't see the most up-to-date information? Try using this component by simply entering data. Refreshing is the responsibility of this component, Get away from data refreshing logic and focus on other things.

Features

  • [X] Flatlist based on infinite scroll page.
  • [X] Take a page and combine them existen pages.
  • [X] When you move to another screen and then come back, only the page you are currently viewing is retrieved and the page in the list is updated.
    • If the page you are currently viewing is between the current page and the next page, both pages will be refreshed.
  • [X] Reset by external request.
  • [X] refresh only the page currently being viewed or a specific page.
  • [X] Props that can utilize caching data

Installation

npm install react-native-fresh-flatlist
# or
yarn add react-native-fresh-flatlist

Usage

function SampleList() {
  const navigation = useNavigation();
  const isFocused = useIsFocused();

  const renderItem = useCallback(
    ({ item, index }: { item: Board; index: number }) => {
      return (
        <Pressable
          style={{ backgroundColor: 'gray', gap: 8, padding: 12 }}
          onPress={() => navigation.navigate('DetailScreen', { item })}
        >
          <View>
            <Text style={{ fontWeight: 'bold' }}>index : {index}</Text>
            <Text>{item.content}</Text>
          </View>

          <Pressable
            onPress={() => {
              // If you want to refresh the page to which the item belongs after changing the status of the item.
              // Example)
              freshFlatListRef.current?.refreshWatching(index);
            }}
          >
            <Text>LIKE!</Text>
          </Pressable>
        </Pressable>
      );
    },
    [navigation]
  );

  const fetchList = useCallback(
    async (fetchInputMeta: FetchInputMeta<T>) => {
      const { fetchPage } = fetchInputMeta;

      // Enter your fetch logic here.
      const response = await fetch(`https://api.example.com/boards?page=${fetchPage}`);
      const data: {
        list: Array<T>;
        isLast: boolean;
      } = await response.json();

      let list: T[] = [];
      if (data && data.list && data.list.length > 0) {
        list = data.list;
      }

      return {
        list: list as Board[],
        isLastPage: data.isLast,
      }
    },
    [category, ownerId, size]
  );

  return (
    <FreshFlatList<T>
      ref={freshFlatListRef}
      isFocused={isFocused}
      fetchList={fetchList}
      renderItem={renderItem}
    />
  )
};

Props

FreshFlatListProps<T>

| Prop | Type | Description | |---------------------|-----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| | fetchList | (fetchInputMeta: FetchInputMeta<T>) => FetchOutputMeta<T> | Required. Function to fetch the list data. | | isFocused | boolean | Optional. refresh watchging list if the screen is focused. | | unshiftData | T[] | Optional. If there is data you want to add in front of data. ex) for filter bar | | initData | T[] | Optional. If you want to reduce fetch by utilizing cached data. ( Not recommended. ) | | fetchCoolTime | number | Optional. Time to prevent the issue of quickly calling the API with the same params multiple times. | | FlatListComponent | ComponentType<FlatListProps<T>> typeof Animated.FlatList<T> | Optional. If you need animation processing using Animated.FlatList or Reanimated.FlatList | | LoadingComponent | ReactNote | Optional. Loading component. |

fetchList Props

FetchInputMeta<T>

| Prop | Type | Description | |-------------------|------------------------------------------|--------------------------------------------------------------------------------| | fetchType | 'first' \| 'watching' \| 'end-reached' | Type of fetch operation. | | fetchPage | number | Page number to fetch. When the fetchList function is first executed, it is 1. | | previousAllData | T[] | Data held by Fresh FlatList before fetchList function was completed. |

FetchOutputMeta<T>

| Prop | Type | Description | |-----------------|-------------|-----------------------------------------------------------------------------------------------| | list | T[] | Required. Fetched list data. Calculated cumulatively within FreshFlatList | | isLastPage | boolean | If you enter true in isLastPage, fetch will not occur even if the end of the list is reached. | | isRenderReady | boolean | The Loading component is displayed until isRenderReady is returned with true at least once. |

FYI

The base of this component is FlatList, so FlatListProps can be used, but the following props cannot be used.

  • 'data' : Fetch data is being accumulated inside the component.
  • 'onEndReached' : When onEndReached is reached, the fetching logic is used internally.

Methods

FreshFlatListRef

| Method | Parameter | Type | Description | |-------------------|-----------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------| | reset | index | number undefined | Resets the list to the initial state. If the index is given, the page containing the index is refreshed. If not, the current watching page is refreshed. | | refreshWatching | void | number | Refreshes the current page of the list. | | flatList | | | This is the "flatList ref" inside the FreshFlatList. |

Hooks

| Hook | Description | |--------------------------|------------------------------------------------------------------------------------------| | usePageKeyMapper | If the API's next fetch information is id-based, this component can be used. | | useCacheInitData | A hook that can help if you want to save caching data and apply it to the initData prop. |

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library