reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
y.khmelevskii 2021-04-15T06:10:55.122900Z

Hey gentlemen, I would like to share that I have added reagent example to emotion-cljs for working with styled components https://github.com/khmelevskii/emotion-cljs/tree/master/examples/reagent-emotion Will be happy if it is useful for somebody

NoahTheDuke 2021-04-19T13:45:26.137600Z

i've never heard of emotion, this is cool as heck

2021-04-15T18:23:30.131Z

I'm trying to call a function navigate on a prop navigation passed to my reactive native component screen from it's parent component Stack. Navigator . The Js equivelent:

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

function HomeScreen({ navigation }) {
  return (
    <View >
      <Button onPress={() => navigation.navigate('Details')}
      />
    </View>
  );
}
However, when i press the Button on my phone i get null is not an object (evaluating 'navigation.navigate') which is telling me navigation is null. How do i correctly get a reference to the navigation object in reagent? Based on the docs, i understand this should be passed directly to my screen function, i had though as part of a map e.g {:navigation (some js object)...}
(defn root []
  [:> paper/Provider {:theme paper/DarkTheme}
   [:> nav/NavigationContainer
    [:> (. stack -Navigator) {:header-mode "none"}
     [:> (. stack -Screen) {:name      "Screen1"
                            :component screen-main}]]]])

(defn screen-main [{:keys [navigation]}] <---- This is clearly not correct, but i'm not sure what would be 
  (r/as-element
    [:> rn/View {:style (tw "flex flex-1")}
     [:> paper/Surface {:style (tw "flex flex-1 justify-center")}
      [:> rn/Button {:title "foo" :onPress #(. navigation navigate "Screen2")}]
      [:> paper/Card
       [:> paper/Card.Title {:title    "screen 1"
                             :subtitle "push up through your hands to get better extension."}]]]]))

2021-04-15T18:37:28.132300Z

maybe it's the case that I have to pass the navigation js object explicitly?

p-himik 2021-04-15T19:02:06.132700Z

You need to use reagent/as-element to wrap the Hiccup that (. stack -Screen) ends up consuming.

p-himik 2021-04-15T19:02:22.132900Z

Reagent repo contains both documentation and multiple examples.

2021-04-15T19:26:33.133500Z

I'm not following, the clojure function screen-main returns a react element because it is warped in reagents as-element function to me, that is the hiccup that (. stack -Screen) consumes.

p-himik 2021-04-15T19:47:53.133700Z

Ah, I'm a bit blind today, apologies. The args should be a regular JS object, so you should be able to use interop to get navigation from there.

2021-04-15T20:17:20.133900Z

that was it, thanks. hmmm, I really thought their was some magic that allowed me to use cljs destructuring. that is, i thought i was getting a clojure hash-map not a js object. I see i can wrap my function in rectify-component if i want to use destructing in the function.

2021-04-15T20:19:31.134100Z

part of the issue is that this is my first adventure into react native land so none of my usual inspection methods are easily at hand (or so it seems)

2021-04-15T20:37:23.134300Z

Though i'm worried i'll need to assign every reactified-component to a var, as if i use it inline it might be doing extra work each time. hmmm