1# Swap Angular Components with React Components with ngReact
2The React.js library can be used as a view component in web applications.
3ngReact is an Angular module that allows React Components to be used in AngularJS applications.
4https://www.npmjs.com/package/ngreact
5
6The angularJs code:
7```
8<li>
9 <h2> Title </h2>
10 <listing-button url=""> Buy now </listing-button>
11<li>
12```
13
14Using Library NGReact:
15```
16<li>
17 <react-component name="listingsTitle" props="..."/>
18 <react-component name="listingsButton" props="..."/>
19<li>
20```
21
22After all sub components are migrated, migrate the full component to React.
23
24```
25import React, {Component} from 'react';
26import ListingsTitle from './listings-title'
27import ListingsButton from './lisitngs-button'
28
29class ListingsItem extends Component {
30 render(){
31 return (
32 <li>
33 <listingsTitle ... />
34 <listingsButton .../>
35 <li>
36 )
37 }
38}
39```
40
41Template:
42```
43<react-component name="listingsItem" props="..."/>
44```
45
46Problem: Unit tests are coupled to code
47Solution: Use Integration Tests temporarily to cover non unit tests covered components.
48
49Source:
50https://javascriptplayground.com/blog/2017/08/migrating-complex-javascript-angular-react/
Created on 10/21/2017