Pullstate

Pullstate

  • Docs
  • GitHub

›Async Action Hooks

Getting Started

  • Installation
  • Quick example
  • Quick example (server rendering)

Reading Store State

  • useStoreState (hook)
  • <InjectStoreState>
  • Subscribe

Updating Store State

  • update()
  • Reactions

Async Actions

  • Introduction
  • Creating an Async Action
  • Use Async Actions
  • Async Action Hooks

    • Hooks overview
    • Post action hook
    • Short circuit hook
    • Cache break hook
  • Other Async Action Options
  • Cache clearing
  • Resolve async state on the server

Dev Tools

  • Redux Devtools

Short circuit hook

The short circuit hook has the following API:

shortCircuitHook({ args, stores }) => false | asyncActionResult

As per all Async Action things, stores here is only available as an option if you are making use of <PullstateProvider> in your app (server-side rendering).

It should either return false or an Async Action result.

If you return an Async Action result, this will effectively "short-circuit" this action. The Promise for this action will not run, and the action will continue from the point directly after that: caching this result, running the post-action hook and finishing.

Be sure to check out the async hooks flow diagram to understand better where this hook fits in.

Example of short circuit

Deciding not to run a search API when the current search term is less than 1 character - return an empty list straight away

shortCircuitHook: ({ args }) => {
  if (args.text.length <= 1) {
    return successResult({ posts: [] });
  }

  return false;
},

In this example, if we have a term that's zero or one character's in length - we short-circuit a successResult(), an empty list, instead of wasting our connection on a likely useless query. If the text is 2 or more characters, we continue with the action.

← Post action hookCache break hook →
  • Example of short circuit
Pullstate
Docs
InstallationA Quick ExampleMore
Community
GitHub
Pullstate
Created by Paul Myburgh