11# Dart wrapper for [ React JS] ( https://reactjs.org/ )
22
33[ ![ Pub] ( https://img.shields.io/pub/v/react.svg )] ( https://pub.dev/packages/react )
4- ![ ReactJS v16.10 .1] ( https://img.shields.io/badge/React_JS-v16.10 .1-green.svg )
4+ ![ ReactJS v17.0 .1] ( https://img.shields.io/badge/React_JS-v17.0 .1-green.svg )
55[ ![ Dart CI] ( https://github.com/Workiva/react-dart/workflows/Dart%20CI/badge.svg?branch=master )] ( https://github.com/Workiva/react-dart/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster )
66[ ![ React Dart API Docs] ( https://img.shields.io/badge/api_docs-react-blue.svg )] ( https://pub.dev/documentation/react/latest/ )
77
@@ -11,7 +11,7 @@ _Thanks to the folks at [Vacuumlabs](https://www.vacuumlabs.com/) for creating t
1111
1212### Installation
1313
14- If you are not familiar with the ReactJS library, read this [ react tutorial] ( http ://facebook.github.io/react /docs/getting-started.html) first.
14+ If you are not familiar with the ReactJS library, read this [ react tutorial] ( https ://reactjs.org /docs/getting-started.html) first.
1515
16161 . Install the Dart SDK
1717
@@ -25,9 +25,9 @@ If you are not familiar with the ReactJS library, read this [react tutorial](htt
2525 name: your_package_name
2626 version: 1.0.0
2727 environment:
28- sdk: ^2.0 .0
28+ sdk: ^2.7 .0
2929 dependencies:
30- react: ^5 .0.0
30+ react: ^6 .0.0
3131 ` ` `
3232
33333. Install the dependencies using pub:
@@ -123,10 +123,10 @@ var aButton = button({"onClick": (SyntheticMouseEvent event) => print(event)});
1231232. Then register the class so ReactJS can recognize it.
124124
125125 ```dart
126- var CoolWidget = registerComponent (() => new CoolWidgetComponent());
126+ var CoolWidget = registerComponent2 (() => CoolWidgetComponent());
127127 ```
128128
129- > __Warning:__ `registerComponent ` should be called only once per component and lifetime of application.
129+ > __Warning:__ `registerComponent2 ` should be called only once per component and lifetime of application.
130130
1311313. Then you can use the registered component similarly as native elements.
132132
@@ -159,7 +159,7 @@ class CoolWidgetComponent extends Component2 {
159159 }
160160}
161161
162- var CoolWidget = registerComponent ( () => new CoolWidgetComponent ());
162+ var CoolWidget = registerComponent2 ( () => CoolWidgetComponent ());
163163` ` `
164164
165165` ` ` dart
@@ -181,14 +181,14 @@ main() {
181181
182182> __Note:__ The typed interface capabilities of this library are fairly limited, and can result in
183183 extremely verbose implementations. We strongly recommend using the
184- [OverReact](https://pub.dartlang.org /packages/over_react) package - which
184+ [OverReact](https://pub.dev /packages/over_react) package - which
185185 makes creating statically-typed React UI components using Dart easy.
186186
187187` ` ` dart
188188// cool_widget.dart
189189typedef CoolWidgetType({String headline, String text, int counter});
190190
191- var _CoolWidget = registerComponent ( () => new CoolWidgetComponent ());
191+ var _CoolWidget = registerComponent2 ( () => CoolWidgetComponent ());
192192
193193CoolWidgetType CoolWidget({String headline, String text, int counter}) {
194194 return _CoolWidget({' headline' :headline, ' text' :text});
@@ -286,7 +286,7 @@ If you want to work with DOM nodes of dart or JS components instead,
286286you can call top level `findDOMNode` on anything the ref returns.
287287
288288```dart
289- var DartComponent = registerComponent (() => new _DartComponent());
289+ var DartComponent = registerComponent2 (() => _DartComponent());
290290class _DartComponent extends Component2 {
291291 @override
292292 render() => div({});
@@ -296,16 +296,16 @@ class _DartComponent extends Component2 {
296296 }
297297}
298298
299- var ParentComponent = registerComponent (() => new _ParentComponent());
299+ var ParentComponent = registerComponent2 (() => _ParentComponent());
300300class _ParentComponent extends Component2 {
301- InputElement inputRef; // Returns the DOM node.
302- _DartComponent dartComponentRef; // Returns instance of _DartComponent
301+ final inputRef = createRef<InputElement>() ; // inputRef.current is the DOM node.
302+ final dartComponentRef = createRef<_DartComponent>() ; // dartComponentRef.current is the instance of _DartComponent
303303
304304 @override
305305 void componentDidMount() {
306- print(inputRef.value); // Prints "hello" to the console.
306+ print(inputRef.current. value); // Prints "hello" to the console.
307307
308- dartComponentRef.someInstanceMethod(5); // Calls the method defined in _DartComponent
308+ dartComponentRef.current. someInstanceMethod(5); // Calls the method defined in _DartComponent
309309 react_dom.findDOMNode(dartComponentRef); // Returns div element rendered from _DartComponent
310310
311311 react_dom.findDOMNode(this); // Returns root dom element rendered from this component
@@ -314,26 +314,26 @@ class _ParentComponent extends Component2 {
314314 @override
315315 render() {
316316 return div({},
317- input({"ref": (ref){ inputRef = ref; } , "defaultValue": "hello"}),
318- DartComponent({"ref": (ref) { dartComponentRef = ref; } }),
317+ input({"ref": inputRef, "defaultValue": "hello"}),
318+ DartComponent({"ref": dartComponentRef}),
319319 );
320320 }
321321}
322322```
323323
324324### Example Application
325325
326- For more robust examples take a look at our [examples](https://github.com/cleandart /react-dart/tree/master/example).
326+ For more robust examples take a look at our [examples](https://github.com/Workiva /react-dart/tree/master/example).
327327
328328
329329
330330## Unit Testing Utilities
331331
332- [lib/react_test_utils.dart](https://github.com/cleandart /react-dart/blob/master/lib/react_test_utils.dart) is a
332+ [lib/react_test_utils.dart](https://github.com/Workiva /react-dart/blob/master/lib/react_test_utils.dart) is a
333333Dart wrapper for the [ReactJS TestUtils](https://reactjs.org/docs/test-utils.html) library allowing for unit tests
334334to be made for React components in Dart.
335335
336- Here is an example of how to use React React.addons.TestUtils. within a Dart test.
336+ Here is an example of how to use `package:react/react_test_utils.dart` within a Dart test.
337337
338338```dart
339339import ' package:test/test.dart' ;
@@ -354,7 +354,7 @@ class MyTestComponent extends react.Component2 {
354354 }
355355}
356356
357- var myTestComponent = react.registerComponent (() => new MyTestComponent());
357+ var myTestComponent = react.registerComponent2 (() => new MyTestComponent());
358358
359359void main() {
360360 test(' should click button and set span text to " success" ' , () {
@@ -391,61 +391,36 @@ Format using
391391dartfmt -l 120 -w .
392392```
393393
394- While we' d like to adhere to the recommended line length of 80, it' s too too short for much of the code
394+ While we' d like to adhere to the recommended line length of 80, it' s too short for much of the code
395395repo written before a formatter was use, causing excessive wrapping and code that' s hard to read.
396396
397- So, we us a line length of 120 instead.
397+ So, we use a line length of 120 instead.
398398
399399# ## Running Tests
400400
401- # ### Dart 2: dart2js
401+ # ### dart2js
402402
403403` ` ` bash
404404pub run test -p chrome
405405` ` `
406406_Or any other browser, e.g. ` -p firefox` ._
407407
408- # ### Dart 2: Dart Dev Compiler ("DDC")
408+ # ### Dart Dev Compiler ("DDC")
409409
410410` ` ` bash
411411pub run build_runner test -- -p chrome
412412` ` `
413413_DDC only works in chrome._
414414
415- # ### Dart 1: Dart VM
416-
417- ` ` ` bash
418- pub run test -p content-shell
419- ` ` `
420-
421- # ### Dart 1: dart2js
422-
423- ` ` ` bash
424- pub run test -p chrome
425- ` ` `
426- _Or any other browser platform, e.g. ` -p firefox` ._
427-
428- # ### Dart 1: Dart Dev Compiler ("DDC")
429-
430- 1. In one terminal, serve the test directory using the dev compiler:
431- ` ` ` bash
432- pub serve test --port=8090 --web-compiler=dartdevc
433- ` ` `
434- 2. In another terminal, run the tests, referencing the port the dev compiler is using to serve the test directory:
435- ` ` ` bash
436- pub run test -p chrome --pub-serve=8090
437- ` ` `
438- _DDC only works in chrome._
439-
440415# ## Building React JS Source Files
441416
442417Make sure the packages you need are dependencies in ` package.json` then run:
443418` ` ` bash
444- npm install
419+ yarn install
445420` ` `
446421
447422After modifying files any files in ./js_src/, run:
448423
449424` ` ` bash
450- npm run build
425+ yarn run build
451426` ` `
0 commit comments