Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jderochervlk/fp-ts-remote-data
https://jderochervlk.github.io/fp-ts-remote-data/
https://github.com/jderochervlk/fp-ts-remote-data
fp fp-ts functional-programming remote-data typescript
Last synced: 9 days ago
JSON representation
https://jderochervlk.github.io/fp-ts-remote-data/
- Host: GitHub
- URL: https://github.com/jderochervlk/fp-ts-remote-data
- Owner: jderochervlk
- Created: 2022-11-04T01:26:29.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-01T06:01:17.000Z (9 months ago)
- Last Synced: 2024-04-04T04:06:09.588Z (9 months ago)
- Topics: fp, fp-ts, functional-programming, remote-data, typescript
- Language: TypeScript
- Homepage:
- Size: 2.04 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @jvlk/fp-ts-remote-data
A library to make it easy to work with remote data. Compatible with the `fp-ts` ecosystem, but it's not required.
RemoteData represents a value that can be in one of four states:
- Loading
- Error
- Empty
- Success[Read the full documentation](https://jderochervlk.github.io/fp-ts-remote-data/).
## Example in React
```tsx
import * as D from '@jvlk/fp-ts-remote-data'
import { pipe } from 'fp-ts/function'import useBlogRequest from './useBlogRequest'
import Loading from './Loading'
import Error from './Error'
import Empty from './Empty'
import Blog from './Blog'function Component() {
const blog = useBlogRequest()return pipe(
blog,
D.fold(
() => ),
err => ,
() => ,
entries =>
)
}
```## Installation
Using NPM:
```
npm i @jvlk/fp-ts-remote-data
```Using Yarn:
```
yarn add @jvlk/fp-ts-remote-data
```## Thanks
The start of this repo began as a clone of https://github.com/sylcastaing/fp-ts-remote-data. I have modified it and diverged from it. That library is much more "sound" from a `fp-ts` types perspective, but I wanted to create something that was focused more on developer usability. I've removed many of the functions in favor of simplifying things. I have also added the 4th state of `empty` to avoid having to use a value of `Option` if the results don't contain any data.
The original concept of the RemoteData type comes from [How Elm Slays a UI Antipattern](http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html).