This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-13
Channels
- # aleph (6)
- # announcements (10)
- # asami (3)
- # babashka (111)
- # babashka-sci-dev (20)
- # beginners (28)
- # calva (28)
- # clj-http (2)
- # clj-kondo (23)
- # cljs-dev (16)
- # cljsrn (23)
- # clojure (116)
- # clojure-czech (3)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (5)
- # clojurescript (41)
- # community-development (2)
- # cursive (5)
- # datahike (4)
- # datomic (13)
- # figwheel-main (3)
- # fulcro (11)
- # google-cloud (1)
- # gratitude (8)
- # hyperfiddle (14)
- # jobs (2)
- # lsp (22)
- # malli (4)
- # off-topic (4)
- # other-languages (4)
- # pathom (13)
- # portal (40)
- # rdf (11)
- # reitit (1)
- # sci (15)
- # shadow-cljs (7)
- # specter (1)
- # sql (6)
- # xtdb (4)
I'm using google maps in my fulcro app - based on example in the fulcro book.
But now I have to switch to another gmaps wrapper. Google provides own react components, way to much to complicated for me. So I selected https://react-google-maps-api-docs.netlify.app/ and ported the code. Basic stuff was easy (with warning You should not pass libraries
prop as new ... please keep an array of libraries as static class property)
(`ui-load-script {:googleMapsApiKey api-key :libraries ["drawing"]}`
(ui-google-map args (ui-marker)))
I have onClick handler which in transaction sets currently selected marker. And app must focus to the selected marker. In old version there is a map attribute "bounds" and when present, the map is properly centered.
Below is an example of panTo javascript. I don't know how to implement call useEffect and from where. Hopefully not from onClick.
function PanningComponent() {
const map = useGoogleMap()
React.useEffect(() => {
if (map) {
map.panTo(...)
}
}, [map])
return null
}
There is a hooks <namespacehttps://book.fulcrologic.com/#reacthooks_support|namespace >https://book.fulcrologic.com/#_react_hooks_support
(defsc PanningComponent [this {:keys [marker]}]
{:query [:marker]
:use-hooks? true}
(let [map (useGoogleMap) ; wherever you got this function from
(hooks/use-effect
#(some-> map (.panTo marker))
[map])))
I'm trying out fulcro's react interop with this library: https://github.com/ydeshayes/react-highlight. I see that we have a default export here https://github.com/ydeshayes/react-highlight/blob/master/src/index.js#L3= so I initially tried importing via:
(ns ...
(:require...
["highlightable$default" :as highlightable]))
(def high (interop/react-factory highlightable))
and afterwards with a couple of other combinations. However I get:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
What am I missing?The import looks right. I typically verify it with (js/console.log highlightable)
Are you suggesting that somewhere in your component you have something like (high {})
but it gives you this error? You could also check what (js/console.log (high {}))
produces...
Exactly @U0522TWDA, when I log out highlightable
I get back a function, and if I try to run (high {})
I get an error:
Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at t$jscomp$0.value (Highlightable.min.js:7:4096)
at t$jscomp$0.value (Highlightable.min.js:7:4096)
at finishClassComponent (react-dom.development.js:20562:31)
at updateClassComponent (react-dom.development.js:20508:24)
at beginWork (react-dom.development.js:22441:16)
at HTMLUnknownElement.callCallback (react-dom.development.js:4162:14)
at Object.invokeGuardedCallbackImpl (react-dom.development.js:4211:16)
at invokeGuardedCallback (react-dom.development.js:4275:31)
at beginWork$1 (react-dom.development.js:27406:7)
at performUnitOfWork (react-dom.development.js:26514:12)
on one hand it would seem that this is a problem in the highlightable library, but maybe that's because I'm not calling it correctly?Hmm, it seems that this call doesn't have the problem, @U0522TWDA :
(high {:ranges []
:enabled true
:onTextHighlighted []
:id "id"
:text "text"})
so it probably was just me calling the actual component in the wrong way. I can debug further from here, thank you 🙏Continuing the train of thought from the library in the question above, now a question on translating react patterns. What I have in fulcro is:
(defmutation add-highlighted-range
"Add a highlighted range"
[{:keys [range]}]
(action [{:keys [state]}]
(swap! state update :ranges
(fn [old-ranges]
(js/console.log "old ranges" old-ranges)
(conj old-ranges range)
))))
(def highlight (interop/react-factory highlightable))
(defsc Root [this {:keys [ranges]}]
{:initial-state {:ranges []}}
(dom/div
(js/console.log "Ranges:" ranges)
(highlight {:ranges ranges
:enabled true
:onTextHighlighted (fn [r]
(comp/transact! this [(add-highlighted-range {:range r})]))
:backgroundStyle {:backgroundColor "#ffcc80"}
:id "1"
:text lorem})))
The text is selected and the props are updated (I see that in the logs), but I get no highlights in the component, and I think it is because I'm not using the component correctly. Here's an example usage:
https://github.com/ydeshayes/react-highlight-example-app/blob/master/src/containers/HighlightApp.js#L57-L66=
I'm mainly confused by the fact that a range object has as a field his parent. I'm not sure even if I have to update the state via a mutation at all. Do you have some insight?I now understand better the pattern in react thanks to https://reactjs.org/docs/state-and-lifecycle.html