Skip to content

Commit e5ba256

Browse files
Merge pull request #3 from divar-ir/add-ssr-sample
Add SSR sample
2 parents 2723316 + 2bbfe76 commit e5ba256

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ Only views can be SSR. Views are components that directly connected to a URL. To
8989

9090
```
9191
Component.propTypes = {
92-
initialSSRData: PropTypes.shape({
93-
posts: PropTypes.array(),
92+
initialSSRData: PropTypes.shape({
93+
posts: PropTypes.array(),
94+
}),
9495
};
9596
9697
export default Component;

src/views/Home/index.jsx

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import MetaTags from 'react-helmet';
34

45
import logo from 'src/assets/logo.svg';
56

7+
import { getHomeTitle } from './requests';
8+
69
import './Home.scss';
710

8-
function Home() {
9-
return (
10-
<main className="container home">
11-
<MetaTags title="divar-starter-kit 🚀" />
12-
<img
13-
className="home__logo"
14-
src={logo}
15-
alt="divar-stater-kit"
16-
/>
17-
<p className="title">Running divar-starter-kit successfully.</p>
18-
</main>
19-
);
11+
class Home extends Component {
12+
static serverSideInitial() {
13+
const title = getHomeTitle();
14+
15+
return {
16+
title,
17+
};
18+
}
19+
20+
render() {
21+
const { initialSSRData: { title } } = this.props;
22+
23+
return (
24+
<main className="container home">
25+
<MetaTags title="divar-starter-kit 🚀" />
26+
<img
27+
className="home__logo"
28+
src={logo}
29+
alt="divar-stater-kit"
30+
/>
31+
<p className="title">{title}</p>
32+
</main>
33+
);
34+
}
2035
}
2136

37+
Home.propTypes = {
38+
initialSSRData: PropTypes.shape({
39+
title: PropTypes.string,
40+
}).isRequired,
41+
};
42+
2243
export default Home;

src/views/Home/requests.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
// eslint-disable-next-line import/prefer-default-export
3+
export function getHomeTitle() {
4+
return 'Running divar-starter-kit successfully.';
5+
}

0 commit comments

Comments
 (0)