Skip to content

listen API & React Hooks support

Compare
Choose a tag to compare
@MZanggl MZanggl released this 26 Jun 23:57
· 15 commits to master since this release

Added

listen API

There is a small but powerful new listen API to catch any state changes. This allows promistate to be used outside of vue-like reactivity systems ( vue, alpine or angular). It opens promistate up for use in react.js, svelte and EVEN Vanilla JS (see README for examples, more coming...).

React hooks support

Thanks to the listen API, promistate now has first-class support for react. Here is an example

import React from "react";
import { usePromistate } from "promistate/lib/react";

export default function App() {
  const [todosPromise, todoActions] = usePromistate(somePromise);
  // todosPromise.value, todosPromise.isPending, ...
  // todoActions.load(), todoActions.reset(), todoActions.setValue('new Value')
}

Fixes

  • Mutating a value directly was previously not causing stale loads to be ignored when ignoreStaleLoad was enabled