Skip to content

Commit 783ed6e

Browse files
committed
Merge pull request #64 from charpeni/issue-63
Add PropTypes to HelloPage on README
2 parents 65f7fc0 + c6f9ad8 commit 783ed6e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ Boom. That's it.
6969
From the "Hello world!"-page you can then navigate further to a new component by calling ```this.props.toRoute()```. Let's build upon the HelloPage component in our first example:
7070

7171
```javascript
72+
import React, { StyleSheet, PropTypes } from 'react-native';
73+
74+
const propTypes = {
75+
toRoute: PropTypes.func.isRequired,
76+
};
77+
7278
class HelloPage extends React.Component {
7379

7480
constructor(props) {
7581
super(props);
7682

7783
this.nextPage = this.nextPage.bind(this);
7884
}
79-
85+
8086
nextPage() {
8187
this.props.toRoute({
8288
name: "A new screen",
@@ -93,8 +99,9 @@ class HelloPage extends React.Component {
9399
</View>
94100
);
95101
}
96-
97102
}
103+
104+
HelloPage.propTypes = propTypes;
98105
```
99106

100107
Now, when you click on "Next page please!", it will go to the next page (which in this case is still HelloPage but with a new title). Keep in mind that ```this.props.toRoute()``` needs to be called from one of the top-level routes, therefore, if your link is deeply nested within multiple components, you need to make sure that the action "bubbles up" until it reaches the parent route, which in turn calls ```this.props.toRoute()```.

0 commit comments

Comments
 (0)