Created
July 5, 2023 13:40
-
-
Save geraldodev/d3721d536110a4cd41ba2725cee7196d to your computer and use it in GitHub Desktop.
defscene with hooks to ilustrate the issue of not being able to use hooks inside defscene plainly, which has the outcome of the code not being captured for portfolio because we have to call a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hooks-test | |
(:require | |
["react" :as React] | |
[portfolio.react-18 :as portfolio :refer-macros [defscene]] | |
)) | |
(defn ComponentExample | |
[props] | |
(let [^js [date _set-date] (React/useState (js/Date.))] | |
(React/createElement "div" nil (str date)))) | |
(defscene SceneWithHooks | |
(React/createElement ComponentExample) | |
;; comment the above line and uncomment this to see the issue | |
; (let [^js [date _set-date] (React/useState (js/Date.))] | |
; (React/createElement "div" nil (str date)) | |
; ) | |
) | |
;; if a hooks is used inside defscene we have the message | |
;; Invalid hook call. Hooks can only be called inside of the body of a function component. T | |
;; https://reactjs.org/link/invalid-hook-call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment