在ClojureScript项目中使用ReactNative外部库-语法



我试图在clojurescript中使用react-native-swipe-list-view。但是我在cljs代码转换文档js代码有一些麻烦。

文件:

import { SwipeRow } from 'react-native-swipe-list-view';
<SwipeRow>
<View>
</View>
</SwipeRow>

我的Cljs代码:

(:require [react-native-swipe-list-view :as swipe_list])
(defn item[]
(
[swipe_list/SwipeRow
[:View]]
))

在线工具:

(def SwipeRow (.-SwipeRow (js/require "react-native-swipe-list-view")))
(defn item[]
(
[SwipeRow
[:View]]
))

以上都不起作用。我是新手。这将是一个很大的帮助,如果有人能告诉我如何将上述行js转换成cljs。由于

试剂文件:创建试剂"组件";from React Components

这里我将创建两个试剂组件,view和swipeRow。我对两者都使用了不同的方式,以展示导入库和创建组件的两种方式。

;; Importing Reagent and React Native
(ns type_name_server_here
(:require [reagent.core :as reagent]
["react-native" :as rn]))

;; 1st Way: Importing SwipeRow
(def SwipeRowImport (.-SwipeRow (js/require "react-native-swipe-list-view")))
;; Converting it into Reagent Component
(def SwipeRow (reagent/adapt-react-class SwipeRowImport))
;; 2nd Way: Importing View from already imported react-native library and converting it into reagent component
(def view (reagent/adapt-react-class (.-View ^js rn)))
;; SwipeRow requires two children (Check out documentation)
(defn item[]
(
[SwipeRow
[view] [view]]
))

如果你正在使用shadow-cljs,你可以使用这个表作为参考,用于将ES6 Import语句转换为CLJS。

最新更新