An open API service indexing awesome lists of open source software.

https://github.com/arifwidianto08/use-lazy-fetch

React utility to perform data fetching , featured with react-hooks too. Created by react-create-library
https://github.com/arifwidianto08/use-lazy-fetch

create-react-library hacktoberfest hacktoberfest-2021 hacktoberfest2021 javascript js react react-typescript reactjs tsx typescript utility

Last synced: 9 days ago
JSON representation

React utility to perform data fetching , featured with react-hooks too. Created by react-create-library

Awesome Lists containing this project

README

        

Owner: Arif Widianto

# use-lazy-fetch

> Performing Data Fetch without initializing state and worrying about useEffect

[![NPM](https://img.shields.io/npm/v/use-lazy-fetch.svg)](https://www.npmjs.com/package/use-lazy-fetch) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save use-lazy-fetch
```

or using `yarn`

```bash
yarn add use-lazy-fetch
```

## Usage

```tsx
import React from 'react'

import { useLazyFetch } from 'use-lazy-fetch'

interface Todo {
data: Array<{
userId: number
id: number
title: string
completed: boolean
}>
}

const App = () => {
const fetchTodos = () => {
return fetch('https://jsonplaceholder.typicode.com/todos')
.then((res) => res.json())
.then((val) => val)
}
const { query, isLoading } = useLazyFetch()
const { data } = query(fetchTodos, [], {
withEffect: true
})

if (isLoading) {
return

'Loading...'

}
return (
{data && data.map((todo) =>

{todo.title}

)}

)
}

export default App
```

## License

## Hacktoberfest

This line is for hacktoberfest thing

Hacktoberfest is the best

MIT © [arifwidianto08](https://github.com/arifwidianto08)