Fork me on GitHub
#cljsrn
<
2019-08-20
>
bartuka02:08:40

hi ppl, I'm sending a parameter to routes but I cannot get the value on the other side. I have to following code on a cell in the first screen

:on-press (fn [] (.navigate (.-navigation (clj->js props)) "Details" {"itemId" 20}))
And when I clicked, I want to get the value in the next screen:
(defn details-screen [props]
  (fn []
    (println (.getParam (.-navigation (clj->js props)) "itemId"))
    [view {:style {:flex 1 :justify-content "center" :align-tems "center"}}
     [text "Details Screen!"]]))

bartuka02:08:26

I can even see the values are being passed correctly if I print the (.-navigation (clj->js props))

#js {:pop #object[Function], :popToTop #object[Function], :push #object[Function], :replace #object[Function], :reset #object[Function], :dismiss #object[Function], :goBack #object[Function], :navigate #object[Function], :setParams #object[Function], :state #js {:params {itemId 20}, :routeName Details, :key id-1566266752816-3}, :router nil, :actions #js {:pop #object[pop], :popToTop #object[popToTop], :push #object[push], :replace #object[replace], :reset #object[reset], :dismiss #object[dismiss], :goBack #object[goBack], :navigate #object[navigate], :setParams #object[setParams]}, :getParam #object[Function], :getChildNavigation #object[getChildNavigation], :isFocused #object[isFocused], :isFirstRouteInParent #object[isFirstRouteInParent], :dispatch #object[Function], :getScreenProps #object[Function], :dangerouslyGetParent #object[Function], :addListener #object[addListener], :emit #object[emit]}

bartuka02:08:39

but I get nil value in the above println

Aklscc02:08:11

Hey, how can we manage state in React native with clojurescript. For example:

[:> rn/Input {:placaeholder "search"
                      :onChangeText #(...)} ]
As we know, the phone input use :onChangeText to watch user's type, and it looks like it will rerender automatically even if we don't set :onChangeText and :value props. But sometimes, we will need to manipulate the input value, such as a clear button. How can do it?

joshmiller03:08:45

@iagwanderson I think your problem with getParam is that you have a CLJ map {"itemId" 20}, which getParam as a JS function doesn’t know how to read into.

joshmiller03:08:37

But I don’t think there’s much reason to use getParam from CLJS, I never do. There’s nothing wrong with treating props as data and just walking into that data structure like a normal Clojure person.

bartuka03:08:04

@joshmiller yes, in the end I did (.-params (.-state (.-navigation (clj->js props)))) and it works just fine

👍 4
bartuka03:08:15

I'm trying to make a request to a backend api (localhost:3000) but I cannot find the origin of the error: {:status 0 :status-text 'Request failed', :failure :failed}

bartuka03:08:47

I had a similar issue inside a re-frame app recently where the problem was related to enabling cors on my backend

bartuka03:08:07

I already enabled it using ring-cors=(

joshmiller03:08:14

The device/simulator probably has its own IP

joshmiller03:08:37

From its perspective, your locally running server is probably at whatever internal IP your machine has

bartuka03:08:10

ohh... let me test, it makes sense

joshmiller03:08:11

Don’t forget you might need to whitelist that for non-secure connections, depending on your setup

joshmiller03:08:29

iOS definitely makes you do that, not sure about Android

bartuka03:08:44

yeah, right on!

bartuka03:08:46

thanks again

bartuka04:08:29

from time to time when I add a new npm dependency I get an error message

Failed to Fetch:  - Perhaps your project was cleaned and you haven't recompiled?
The process I follow is 1) run npm install <package> --save 2) react-native link 3) require the dependency inside my project E.x. (js/require "react-native-action-button") 4) re-natal use-figwheel (which finds the required package and adds it to index.android.js) and finally lein figwheel android

bartuka04:08:31

Am I doing something wrong here? The weird thing for me is not detecting a clear pattern about this issue. With some dependencies everything goes well and others don't