1.0.5 • Published 9 months ago

loki-usefetch v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Example

import React from 'react';
import { useFetch } from 'loki-usefetch';

const TestComponent = () => {
  const [currentPage, setCurrentPage] = useState(1);

  // Use the useFetch hook with the API URL and current page
  const { data, isLoading, isError, refetch } = useFetch<DataItem>(
    'https://example-api.com/data',
    currentPage
  );

  // Define the type/interface representing your data item
  interface DataItem {
    id: number;
    name: string;
    // Add other properties as needed
  }

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (isError) {
    return (
      <div>
        <div>Error: {isError}</div>
        <button onClick={() => refetch(currentPage)}>Retry</button>
      </div>
    );
  }

  return (
    <div>
      {data && data.map((item) => <div key={item.id}>{item.name}</div>)}
      <button onClick={() => setCurrentPage((prevPage) => prevPage + 1)}>Next Page</button>
      <button onClick={() => refetch(currentPage)}>Refresh Data</button>
    </div>
  );
};

export default TestComponent;
1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago