You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-25Lines changed: 40 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,20 @@ A ClojureScript wrapper for React.
4
4
5
5
There are a number of React-like libraries for ClojureScript (e.g., Om, Reagent, Rum). Many use React under the covers.
6
6
7
-
By contrast, this library simply exposes an interface to React in a ClojureScript-friendly way. It is for developers who, like myself, want to use React directly from a ClojureScript application.
7
+
By contrast, this library simply exposes an interface to React in a ClojureScript-friendly way. It is for developers who, like myself, want to use React directly from ClojureScript.
8
+
9
+
## Goodies
10
+
11
+
-**Built-in support for hot-reloading**. If you use, for example, Figwheel to hot-reload files on change, React components created with the `defc` macro will be patched automatically.
12
+
-**Method tracing**. Including `:trace? true` in the class definition map will cause every method call to emit a message to the console. This also attempts to break infinite loops by setting a ceiling on the number of traces in a short time period.
13
+
-**React Developer Tools support**. Copies component state and props into plain JavaScript in non-optimized compilation modes so it is easier to use React Developer Tools (Chrome extension) to inspect components.
8
14
9
15
### Add dependency:
10
16
11
17
```clj
12
18
[dmohs/react "0.2.12"]
13
19
```
14
20
15
-
### Quickstart Template:
16
-
17
-
```bash
18
-
lein new dmohs.cljs-react my-project
19
-
```
20
-
21
-
See [dmohs.cljs-react template](https://github.com/dmohs/cljs-react-template) for usage.
22
-
23
21
## Top-Level API
24
22
25
23
The Top-Level API closely follows React's Top-Level API:
@@ -93,11 +102,9 @@ The `render` method can return either an element or a vector (as in the above ex
93
102
### ReactDOM.render
94
103
95
104
```clj
96
-
(react/render element container callback hot-reload?)
105
+
(react/render element container callback)
97
106
```
98
107
99
-
If `hot-reload?` is true, component state will be preserved before unmounting and loaded into the newly-rendered tree. This makes Figwheel usage quite easy. I usually pass `goog.DEBUG` as this parameter so it is automatically turned off for minimized/production builds.
100
-
101
108
### ReactDOM.unmountComponentAtNode
102
109
103
110
```clj
@@ -107,7 +114,7 @@ If `hot-reload?` is true, component state will be preserved before unmounting an
React methods are defined using Clojure naming conventions (`:get-initial-state` corresponds to `getInitialState`). Additional methods become part of the object, so `:add-foo` can be called like so:
126
+
React methods are defined using Clojure naming conventions (`:get-initial-state` corresponds to `getInitialState`). Additional methods become part of the object (as in React), so `:add-foo` can be called like so:
120
127
```clj
121
128
(react/call:add-foo this "argument 1""argument 2")
Methods are passed a map with the appropriate keys defined:
@@ -144,12 +153,18 @@ Methods are passed a map with the appropriate keys defined:
144
153
}
145
154
```
146
155
147
-
1. This is used when you would pass a callback to `setState`, e.g., `(after-update #(.focus (react/find-dom-node this)))`.
148
-
2. The `refs` atom allows accessing `this.refs` as a map (e.g., `(.focus (@refs "my-text-box"))`).
149
-
3. Convenience atom for local variables. Instead of, e.g., `(set! (.-myTimer this) (js/setTimeout ...))`, you can do `(swap! locals assoc :my-timer (js/setTimeout ...))`.
156
+
1. This is used when you would pass a callback to `setState`, e.g.,
Note: for non-api methods (like `:add-foo` above), this map is the first argument before any arguments passed when calling the method using `react/call`.
152
167
153
168
Modifying the `state` atom implicitly calls `this.setState`. This maintains the behavior of React's `this.state` in the way that updates (via `swap!` or `reset!`) are not visible in `@state` until after the component is re-rendered.
154
169
155
-
Note that `propTypes`, `statics`, and `mixins` are not yet implemented.
170
+
Note that `propTypes`, `statics`, and `mixins` are not yet implemented. They may never be, since Clojure to some extent obviates the need for some of these utilities.
0 commit comments