react 2021-08-24

this is a great discussion for library authors: https://github.com/reactwg/react-18/discussions/84

"useMutableSource and selector stability"

seems v relevant for people maintaining or building libraries for managing state external from React

I'm working on a library for interacting with React from a REPL

currently you can look up an instance of a component on the page (called a fiber) and get things like props, state, and children

(require '[react-repl.core :as rr])

(rr/find my-component)
;; => #object[FiberNode]

(-> (rr/find my-component)
    (rr/state))
;; => ({:type "useState", :current {:name "foo"}, :dispatch #object[dispatch]} {:type "useCallback" :current #js [object[Function] #js []]})

(-> (rr/find my-component)
    (rr/props))
;; => {:initial-name "foo"}

(-> (rr/find my-component)
    (rr/state)
    (first)
    (rr/hook-dispatch {:name "bar"}))
;; => {:name "bar"}

(-> (rr/find my-component)
    (rr/state))
;; => ({:type "useState", :current {:name "bar"}, :dispatch #object[dispatch]} {:type "useCallback" :current #js [object[Function] #js []]})

❤️ 2