Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit 22847fb

Browse files
committed
Use function components in example/readme
1 parent f9ac87f commit 22847fb

File tree

3 files changed

+46
-56
lines changed

3 files changed

+46
-56
lines changed

README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ Your views should be node modules that export a React component. Let's assume yo
5353
```js
5454
var React = require('react');
5555

56-
class HelloMessage extends React.Component {
57-
render() {
58-
return <div>Hello {this.props.name}</div>;
59-
}
56+
function HelloMessage(props) {
57+
return <div>Hello {props.name}</div>;
6058
}
6159

6260
module.exports = HelloMessage;
@@ -90,15 +88,13 @@ Simply pass the relevant props to a layout component.
9088
```js
9189
var React = require('react');
9290

93-
class DefaultLayout extends React.Component {
94-
render() {
95-
return (
96-
<html>
97-
<head><title>{this.props.title}</title></head>
98-
<body>{this.props.children}</body>
99-
</html>
100-
);
101-
}
91+
function DefaultLayout(props) {
92+
return (
93+
<html>
94+
<head><title>{props.title}</title></head>
95+
<body>{props.children}</body>
96+
</html>
97+
);
10298
}
10399

104100
module.exports = DefaultLayout;
@@ -109,14 +105,12 @@ module.exports = DefaultLayout;
109105
var React = require('react');
110106
var DefaultLayout = require('./layouts/default');
111107

112-
class HelloMessage extends React.Component {
113-
render() {
114-
return (
115-
<DefaultLayout title={this.props.title}>
116-
<div>Hello {this.props.name}</div>
117-
</DefaultLayout>
118-
);
119-
}
108+
function HelloMessage(props) {
109+
return (
110+
<DefaultLayout title={props.title}>
111+
<div>Hello {props.name}</div>
112+
</DefaultLayout>
113+
);
120114
}
121115

122116
module.exports = HelloMessage;

examples/simple/views/index.jsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ function countTo(n: number): string {
1111
return a.join(', ');
1212
}
1313

14-
class Index extends React.Component {
15-
render() {
16-
return (
17-
<Layout title={this.props.title}>
18-
<h1>{this.props.title}</h1>
19-
<p>Welcome to {this.props.title}</p>
20-
<p>
21-
I can count to 10:
22-
{countTo(10)}
23-
</p>
24-
</Layout>
25-
);
26-
}
14+
function Index(props) {
15+
return (
16+
<Layout title={props.title}>
17+
<h1>{props.title}</h1>
18+
<p>Welcome to {props.title}</p>
19+
<p>
20+
I can count to 10:
21+
{countTo(10)}
22+
</p>
23+
</Layout>
24+
);
2725
}
2826

2927
Index.propTypes = {

examples/simple/views/layout.jsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
var React = require('react');
22
var PropTypes = require('prop-types');
33

4-
class Layout extends React.Component {
5-
render() {
6-
return (
7-
<html>
8-
<head>
9-
<title>{this.props.title}</title>
10-
<link rel="stylesheet" href="/stylesheets/style.css" />
11-
<script
12-
dangerouslySetInnerHTML={{
13-
__html: `
14-
// This is making use of ES6 template strings, which allow for
15-
// multiline strings. We specified "{jsx: {harmony: true}}" when
16-
// creating the engine in app.js to get this feature.
17-
console.log("hello world");
18-
`,
19-
}}
20-
/>
21-
</head>
22-
<body>{this.props.children}</body>
23-
</html>
24-
);
25-
}
4+
function Layout(props) {
5+
return (
6+
<html>
7+
<head>
8+
<title>{props.title}</title>
9+
<link rel="stylesheet" href="/stylesheets/style.css" />
10+
<script
11+
dangerouslySetInnerHTML={{
12+
__html: `
13+
// This is making use of ES6 template strings, which allow for
14+
// multiline strings. We specified "{jsx: {harmony: true}}" when
15+
// creating the engine in app.js to get this feature.
16+
console.log("hello world");
17+
`,
18+
}}
19+
/>
20+
</head>
21+
<body>{props.children}</body>
22+
</html>
23+
);
2624
}
2725

2826
Layout.propTypes = {

0 commit comments

Comments
 (0)