Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/rmdort/react-usesuspense
- Owner: rmdort
- Created: 2020-05-12T17:56:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T05:42:56.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T18:48:58.089Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 26.2 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: Readme.md
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'))
````