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.You have to use a function component. Reagent has great documentation on the topic.
Got it. Thank you. I wonder if I use r/createElement to create function component can I use hook?
I didn’t find this info in the documentation
https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#function-components