💾
FloppyDisk.JS
DocsDocsExamplesExamplesBlogBlog
GitHubGitHub (opens in a new tab)
  • Getting Started
  • Comparison
    • Introduction
    • Store Event
    • Interception
    • Watch Component
    • Silent Update
    • As Local State
    • Persist State
    • With Immer
    • Introduction
    • Stores Event
    • Introduction
    • Single Query
    • Single Query with Params
    • Network Mode
    • Paginated/Infinite Query
    • Dependent Queries
    • Initial Query Data (SSR/SSG)
    • Error Retries
    • Lazy Query
    • Disabling Query
    • Prefetching
    • Query Invalidation
    • Optimistic Update
    • Window Focus Refetching
    • Auto Refetching / Polling
    • Suspense
    • Custom Logger
    • Query Cancellation
    • Introduction
    • Invalidation from Mutation
    • Update from Mutation Response
    • Optimistic Update
    • Offline Mutation
  • TypeScript
  • GraphQL
  • React Native
  • Firebase/Supabase Integration

  • API
  • Experimental Features

  • Change Log ↗ (opens in a new tab)
Question? Give us feedback → (opens in a new tab)Edit this page on GitHub →
Docs
Store
Interception

Interception

const useCatStore = createStore(
  ({ set }) => ({
    age: 0,
    isSleeping: false,
    increaseAge: () => set((state) => ({ age: state.age + 1 })),
    reset: () => set({ age: 0, isSleeping: false }),
  }),
  {
    intercept: (nextState, prevState) => {
      if (nextState.age !== prevState.age) {
        return { ...nextState, isSleeping: false };
      }
      return nextState;
    },
  },
);
ℹ️

Example: https://codesandbox.io/.../examples/react/intercept (opens in a new tab)

Store EventWatch Component

MIT 2024 © Nextra.