Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/rmdort/react-usesuspense

[deprecated]. Use SWR instead. Experimenting with suspending hooks
https://github.com/rmdort/react-usesuspense

Last synced: 18 days ago
JSON representation

[deprecated]. Use SWR instead. Experimenting with suspending hooks

Awesome Lists containing this project

README

        

## Experimenting with suspending hook

(Use at your own risk)

## Installation

```
npm install https://github.com/rmdort/react-usesuspense
```

## Usage

````
import React, { Suspense } from 'react
import useSuspense from 'react-usesuspense'

const SearchResults = ({ query }) => {
const api = useMemo(() => {
return fetch(`https://hn.algolia.com/api/v1/search_by_date?tags=story&query="${query}"`)
}, [ query ])
const results = useSuspense(() => {
return api.then(res => res.json()).then(res => res.hits)
}, [ api ])
return (


{results.map((result, idx) => {
return (

{result.title}

)
})}

)
}

const App = () => {
const [ query, setQuery ] = useState('')
return (


setQuery(e.target.value)} />
Loading
}>



)
}

ReactDOM.render(, document.getElementById('root'))

````