hx
fully embraces vanilla React development; it does not provide any
additional functionality than the core React library.
However, React already provides a rich API for doing state management and other common effects in a UI application: React Hooks.
React Hooks are a powerful system for representing side effects we want to occur while our application is operating such as changing state, firing network requests, subscribing to external sources, etc.
hx
provides a small helper library called hx.hooks
that offers a
Clojure-first API to the React Hooks API.
You may also leverage any Hooks libraries that you may find, since hx
components are pure React components that are compatible with all of the
external React ecosystem.
The idiom that this library provides is: any Hook is named like useAbcXyz
to
provide at-a-glance recognition of what Hooks a component uses.
All of the Rules of Hooks apply.
Same as react/useState. Takes an initial value. Returns a tuple [value set-value]
, where set-value
is a function that can be used like swap!
:
;; a raw value
(set-value {:this-is "new state"})
;; a function to apply
(set-value (fn [old-state] (conj old-state :updated)))
;; a function to apply and arguments to prepend
(set-value conj :update)
Takes an initial value. Returns an atom that will NOT re-render component on change.
Just react/useReducer.
Just react/useEffect.
deps
can be a CLJS collection.
Just react/useContext.
Just react/useMemo.
deps
can be a CLJS collection.
Caches x
. When a new x
is passed in, returns new x
only if it is
not equal to the previous x
.
Useful for optimizing useEffect
et. al. when you have two values that might
be structurally equal by referentially different.
Just react/useCallback.
Just react/useImperativeHandle.
deps
can be a CLJS collection.
Just react/useLayoutEffect.
deps
can be a CLJS collection.
Just react/useDebugValue.
deps
can be a CLJS collection.
Can you improve this documentation? These fine people already did:
Will Acton & UbuntuEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close