reagent

Amos 2023-06-17T13:12:32.104059Z

Hi, I try to translate the slatejs library into reagent. The following is the original code:

const App = () => {
  const [editor] = useState(() => withReact(createEditor()))
  // Render the Slate context.
  return <Slate editor={editor} initialValue={initialValue} />
}
This is what I try to do:
(defn block [initialValue]
  #?(:cljs
     (let [[editor]
           (react/useState
            (fn [] (withReact (createEditor))))]
       [:> Slate {:editor editor :initialValue (clj->js initialValue)}])))
However, the error mentioned that the hook can’t not be at the outside of function component. I wonder how to fix this problem.

p-himik 2023-06-17T13:14:17.983319Z

You have to use a function component. Reagent has great documentation on the topic.

Amos 2023-06-17T14:06:49.665009Z

Got it. Thank you. I wonder if I use r/createElement to create function component can I use hook?

Amos 2023-06-17T14:06:59.827379Z

I didn’t find this info in the documentation