https://github.com/illusionalsagacity/rescript-use-subscription
Zero-cost ReScript bindings for use-subscription
https://github.com/illusionalsagacity/rescript-use-subscription
Last synced: 8 months ago
JSON representation
Zero-cost ReScript bindings for use-subscription
- Host: GitHub
- URL: https://github.com/illusionalsagacity/rescript-use-subscription
- Owner: illusionalsagacity
- License: mit
- Created: 2021-08-06T02:10:03.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-03T17:17:31.000Z (over 3 years ago)
- Last Synced: 2024-08-03T01:29:04.818Z (over 1 year ago)
- Language: ReScript
- Size: 4.88 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - rescript-use-subscription - cost ReScript bindings for use-subscription | illusionalsagacity | 4 | (ReScript)
README
# rescript-use-subscription
## ⚠️ Deprecated
The `use-subscription` package is now just a wrapper for `use-sync-external-store`. New bindings can be found [here](https://github.com/illusionalsagacity/rescript-use-sync-external-store) with migration instructions.
This is a zero-cost ReScript binding package for use with [use-subscription](https://github.com/facebook/react/tree/main/packages/use-subscription)
## Usage
Usage is essentially the same as the javascript package:
```reasonml
let {useSubscription} = module(UseSubscription)
@react.component
let make = () => {
let options = React.useMemo(() => {
UseSubscription.getCurrentValue: () => Some(1),
subscribe: callback => {
callback(. Some(1))
(.) => ()
},
})
let val = useSubscription(options)
{val->Belt.Option.mapWithDefault(React.null, React.int)}
}
```
Uncurried functions are used to eliminate overhead from the ReScript generated output.