Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created July 5, 2023 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/d3721d536110a4cd41ba2725cee7196d to your computer and use it in GitHub Desktop.
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
(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