JSPM

rescript-use-sync-external-store

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q29376F
  • License MIT

ReScript bindings to use-sync-external-store

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rescript-use-sync-external-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    rescript-use-sync-external-store

    This is a zero-cost ReScript binding to use-sync-external-store. Specifically to use-sync-external-store/shim.

    Usage

    See __test__/SyncExternalStore_test.res for usage.

    Migration from use-subscription

    If you were using rescript-use-subscription before, migration should be fairly straightforward:

    Before

    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)
    
      <div>{val->Belt.Option.mapWithDefault(React.null, React.int)}</div>
    }

    After

    let val = ref(Some(1))
    
    @react.component
    let make = () => {
      let val = SyncExternalStore.use(
        ~getSnapshot=() => val.contents,
        ~subscribe=callback => {
          callback()
          () => ()
        },
        (),
      )
    
      <div> {val->Belt.Option.mapWithDefault(React.null, React.int)} </div>
    }