This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-12
Channels
- # announcements (3)
- # babashka (6)
- # beginners (84)
- # biff (1)
- # cider (7)
- # cljsrn (1)
- # clojure (18)
- # clojure-australia (3)
- # clojure-dev (21)
- # clojure-france (1)
- # clojure-spec (6)
- # clojurescript (78)
- # datomic (34)
- # emacs (5)
- # exercism (32)
- # graalvm (1)
- # helix (2)
- # hyperfiddle (3)
- # lsp (36)
- # malli (4)
- # missionary (3)
- # off-topic (54)
- # re-frame (14)
- # releases (2)
- # sql (31)
- # vim (9)
I want to convert the following to cljs (reagent), but don’t really understand how to do the part that’s nested inside the <Dropzone> tag:
<Dropzone onDrop={acceptedFiles => console.log(acceptedFiles)}>
{({getRootProps, getInputProps}) => (
<section>
<div {...getRootProps()}>
<input {...getInputProps()} />
<p>Drag 'n' drop some files here, or click to select files</p>
</div>
</section>
)}
</Dropzone>
Reagent repo has multiple examples covering all such cases. For example, https://github.com/reagent-project/reagent/blob/c214466bbcf099eafdfe28ff7cb91f99670a8433/doc/InteropWithReact.md#example-function-as-child-components
I’m using the following library to do file drop into the browser: https://github.com/tonsky/cljs-drag-n-drop And this is my component (using useRef):
(defn i-have-a-creation []
(let [drop-ref (useRef nil)]
(try (dnd/subscribe! drop-ref :unique-key
{:start (fn [e] (println "d1 start"))
:enter (fn [e] (println "d1 enter"))
:drop (fn [e files] (println "d1 drop"))
:leave (fn [e] (println "d1 leave"))
:end (fn [e] (println "d1 end"))})
(catch js/Object e (prn e)))
[:div
[:div.drop {:ref (fn [r] drop-ref)} "Drop here"]]))
Although the d1 start and d1 end events are fired when I bring in the file in the browser window, when I drop the file inside div.drop, it doesn’t trigger the leave event but instead opens the file in a new tab. Does anyone know how to fix this?you can't use a library not designed for react with react. well at least it'll require a lot more interop to get the correct thing to the correct places. your use of drop-ref is incorrect and the dnd/subscribe would need to be in a proper hook so it only runs on mount (and properly unsubscribes on unmount)
I tried the following:
(defn i-have-a-creation []
(let [drop-ref (js/document.querySelector "div#drop")]
(try (dnd/subscribe! drop-ref :unique-key
{:start (fn [e] (println "d1 start"))
:enter (fn [e] (println "d1 enter"))
:drop (fn [e files] (println "d1 drop"))
:leave (fn [e] (println "d1 leave"))
:end (fn [e] (println "d1 end"))})
(catch js/Object e (prn e)))
[:div.sell-royalties-page
[:div.drop {:id :drop} "Drop here"]]))
even thought the start and end events are firing dropping the file into the Drop here div opens it in a new tab?you already pasted that code. I told you whats wrong with it. sorry can't go into more detail right now
@U05224H0W this one uses querySelector not useRef?
with id?
like in the docs of the library?
I made this example some time ago https://github.com/thheller/reagent-pdfjs/blob/master/src/main/demo/app.cljs
did anyone implement a live search form in clojurescript, I have to pull the text from the external api store it in array and then create an input label which gives suggestion to the user
There's plethora of JS components that do that, for all sorts of UI libraries - you can just use one of them without having to reinvent the wheel.
can you suggest some of them ? I am new to clojure
As I said - it has nothing to do with Clojure. It would be a JavaScript library/component, and it depends on what you're already using. I would have to do the same web search as you, only I'm at disadvantage of not having the information on what you use.
well I am using reagent
And it uses React. So you can search online for "life search form react" or, since it's more commonly called "typeahead", "typeahead react".
I have another query sir , I am retrieving a request using (defn get-json [url] (GET url ;;:params params ;;:handler (partial success-handler function-handler) ;;:error-handler error-handler :format (json-request-format) :response-format (json-response-format {:keywords? true}))) (def all-symbols (get-json "https://ai.almanac.ai/db/api/data/symbol/search?q="))
and I am getting #object[Object [object Object]] how to convert it into map
no effect
can you suggest me where to learn how to fetch GET request and convert it into clojure maps
The documentation of whatever you're using to issue the requests? You're using GET
in your code - it belongs to some library, which probably has documentation.
i am using this
yes can't find related error
(defn select-input [id label options data] (r/with-let [value (re-frame/subscribe [::subs/form id]) ] [:div.field [:label.label label] [:div.control [:div.select [:> js/Select { :class "form-input" :value @value :options test-options :multi true :placeholder "Select" :on-change (fn [event] (reset! value event) (re-frame/dispatch [::events/update-form id event]) ) }] ]]]))
I would suggest that you try out the component with hard coded values to find out how the component api is built. Then add re-frame subscriptions and dispatch events. Even better, I think you could extract the dispatch events and subscriptions to separate functions, and pass them in as params to your component.
Can you help me with an example? I am not good at re-frame and clojurescript. Thanks
Maybe this example code can help and inspire you try out different approaches (this one is a text-field with “on-change” events): https://github.com/DavidVujic/clojurescript-amplified/blob/main/src/main/app/components/user.cljs#L21
Or this one (a less code): https://github.com/DavidVujic/clojurescript-amplified/blob/main/src/main/app/components/top.cljs#L4
The general idea is to keep your components simple, pass in actions like “on-click”. You can also pass in values. When doing that, your component does not have to know about any re-frame code at all.
Okay, Thanks @U018VMC8T0W
https://github.com/JulianBirch/cljs-ajax/blob/master/docs/formats.md I use the ajax/get function from this library to fetch the get request from the api, but I am geeeting object only how to solve this
I am trying to replicate this query
with this
what is handler function I am pretty new to clojure and stuck in complicated task
The handler function is the clojure function that will receive the return of the get-request
what should be my handler function
i just want to fetch the get request and store it in variable
You could try something like
(def state (atom {}))
(defn my-handler [response]
(swap! state assoc :all-symbols response))
This puts the response inside an atom, later you can retrieve it with (get @state :all-symbols)
or just (:all-symbols @state)
.
If you're running that code in the browser, don't use REPL to inspect JS values (and #object[...]
is a JS value) - instead, pass it to (js/console.log ...)
and inspect it inside your browser's JS console. It will tell you what kind of object it is and will help you reason about why you receive it.
Thanks brother it works
I am using this code
how to access the data key from the state atom
I am using (:data @atom_name) but it is not working
No clue. I can take a look if you create a public minimal reproducible example on GitHub or any other place.
i just want to access the map inside the map, retrieved data looks something like this
you know about centipar library of clojurescript ?
I have to solve this issue , I am kind of stuck in it
maybe my company make it private
["Algeria" , "Comp" , "Malaria" , "Xenophones"] I am to filter out the words which contains "a" in it I am trying (filter includes "a" words) it is not working
1. You gotta provide the code if you want help 2. You gotta use a thread for a single purpose - ask new questions at the top level of a suitable channel
The code is quite abrupt and makes no sense at all I am trying to optimize it, you help me a lot I quite appreciate it
(def words ["axs" , "sdsa" ,"clj" , "xyz"]) (defn include_word [letter list] (for [n list] (includes n letter)) (def include_a? (partial include_word "a")) (filter include_a? words)
I am using this code