Updated the readme.md and grouped the new tests

This commit is contained in:
Matias Ribichich
2017-03-16 10:32:19 -03:00
parent d59b511d74
commit 740313d72b
2 changed files with 32 additions and 59 deletions
+9 -38
View File
@@ -17,44 +17,6 @@ npm install react2angular --save
```js
import { Component } from 'react'
class MyComponent extends Component {
render() {
return <div>
<p>FooBar: {this.props.fooBar}</p>
<p>Baz: {this.props.baz}</p>
</div>
}
}
```
### 2. Expose it to Angular
```js
import { react2angular } from 'react2angular'
angular
.module('myModule', [])
.component('myComponent', react2angular(MyComponent, ['fooBar', 'baz']))
```
### 3. Use it in your Angular 1 code
```html
<my-component
foo-bar="3"
baz="'baz'"
></my-component>
```
## Usage 2 (Alternative)
As an alternative you can specify the propTypes in your component, and it'll be use automatically as the bindings
### 1. Create a React component
```js
import { Component } from 'react'
class MyComponent extends Component {
static propTypes = {
fooBar: React.PropTypes.number.isRequired,
@@ -72,6 +34,8 @@ class MyComponent extends Component {
### 2. Expose it to Angular
When propTypes are specified, they'll be used as the component's bindings, so it's no necessary to add them again.
```js
import { react2angular } from 'react2angular'
@@ -80,6 +44,13 @@ angular
.component('myComponent', react2angular(MyComponent))
```
As an alternative you can pass the bindings and they'll override the use of propTypes.
```js
// ...
.component('myComponent', react2angular(MyComponent, ['fooBar', 'baz']))
```
### 3. Use it in your Angular 1 code
```html