reagent.hooks

React hooks that use Clojure value equality for deps and state.

use-action-statefunction

(use-action-state f initial-state)
(use-action-state f initial-state permalink)

Update state based on the result of a form action.

Source

use-callbackfunction

(use-callback f dependencies)

Cache a function between re-renders.

Differences to React.js:

  • Dependency comparison is using clojure equality vs React.js uses Object.is which would only work for JS primitive values.
Source

use-clj-depsfunction

(use-clj-deps deps)

Check the new clj deps value against the previous value, stored in a ref hook, so we can use clj equality check to see if the value changed.

Only not= value is stored to the ref, so the effect dependency value only updates when the equality changed.

Source

use-contextfunction

(use-context ctx)

Read and subscribe to React Context.

Source

use-debug-valuefunction

(use-debug-value value)
(use-debug-value value format)

Add a label to custom Hook in React Devtools.

Source

use-deferred-valuefunction

(use-deferred-value value)

Defer updating a part of the UI.

Source

use-effectfunction

(use-effect setup)
(use-effect setup dependencies)

Run side-effect on component mount or dependency changes.

If the setup fn returns a function, that will be used as a cleanup function, and will run on unmount, or when depenendecies changes.

Dependency changes consider Clojure value equality, i.e., you can use clojure maps and other data structures in the dependencies vector.

Differences to React.js:

  • Any non-fn return value from setup fn is considered to mean no cleanup fn is used, vs React.js requires undefined to be returned.
  • Dependency comparison is using clojure equality vs React.js uses Object.is which would only work for JS primitive values.
Source

use-idfunction

(use-id)

Generate unique ID that can be passed to accessibility attributes.

Source

use-imperative-handlefunction

(use-imperative-handle ref create-handler)
(use-imperative-handle ref create-handler dependencies)

Customize the handle exposed as a ref.

Source

use-layout-effectfunction

(use-layout-effect setup)
(use-layout-effect setup dependencies)

Version of use-effect that fires before the browser repaints the screen.

If the setup fn returns a function, that will be used as a cleanup function, and will run on unmount, or when depenendecies changes.

Dependency changes consider Clojure value equality, i.e., you can use clojure maps and other data structures in the dependencies vector.

Differences to React.js:

  • Any non-fn return value from setup fn is considered to mean no cleanup fn is used, vs React.js requires undefined to be returned.
  • Dependency comparison is using clojure equality vs React.js uses Object.is which would only work for JS primitive values.
Source

use-memofunction

(use-memo calculate-value dependencies)

Cache the result of a calculation between re-renders.

Dependency changes consider Clojure value equality, i.e., you can use clojure maps and other data structures in the dependencies vector.

Differences to React.js:

  • Dependency comparison is using clojure equality vs React.js uses Object.is which would only work for JS primitive values.
Source

use-optimisticfunction

(use-optimistic state update-fn)

Optimistically update the UI

Source

use-reducerfunction

(use-reducer reducer initial-arg)
(use-reducer reducer initial-arg init)

Create a state store that is updated by calling reducer with the current state and a dispatch event.

Differences to React.js:

  • The result of reducer fn is compared to the previous state value using clojure equality check, and if the value is equal, the previous state is kept. This ensures React.js Object.is check for checking if the state changed works.
Source

use-reffunction

(use-ref v)

Keep a reference to a value that is not needed for rendering.

Source

use-statefunction

(use-state initial-state)

Create a state store

Differences to React.js:

  • The new state is compared to the old state using clojure equality, and if the value is equal, the previous state is kept. This ensures React.js Object.is check for checking if the state changed works.
Source

use-sync-external-storefunction

(use-sync-external-store subscribe get-snapshot)
(use-sync-external-store subscribe get-snapshot get-server-snapshot)

Subscribe to an external store.

Source

use-transitionfunction

(use-transition)

Render a part of the UI in the background.

Source

with-return-value-checkfunction

(with-return-value-check f)

Consider any non-fn value from effect callbacks as no callback.

Source