Skip to content

Commit

Permalink
Merge pull request #3 from divar-ir/add-ssr-sample
Browse files Browse the repository at this point in the history
Add SSR sample
  • Loading branch information
iMohammadReza authored Jun 6, 2021
2 parents 2723316 + 2bbfe76 commit e5ba256
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ Only views can be SSR. Views are components that directly connected to a URL. To

```
Component.propTypes = {
initialSSRData: PropTypes.shape({
posts: PropTypes.array(),
initialSSRData: PropTypes.shape({
posts: PropTypes.array(),
}),
};
export default Component;
Expand Down
47 changes: 34 additions & 13 deletions src/views/Home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import React from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import MetaTags from 'react-helmet';

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

import { getHomeTitle } from './requests';

import './Home.scss';

function Home() {
return (
<main className="container home">
<MetaTags title="divar-starter-kit 🚀" />
<img
className="home__logo"
src={logo}
alt="divar-stater-kit"
/>
<p className="title">Running divar-starter-kit successfully.</p>
</main>
);
class Home extends Component {
static serverSideInitial() {
const title = getHomeTitle();

return {
title,
};
}

render() {
const { initialSSRData: { title } } = this.props;

return (
<main className="container home">
<MetaTags title="divar-starter-kit 🚀" />
<img
className="home__logo"
src={logo}
alt="divar-stater-kit"
/>
<p className="title">{title}</p>
</main>
);
}
}

Home.propTypes = {
initialSSRData: PropTypes.shape({
title: PropTypes.string,
}).isRequired,
};

export default Home;
5 changes: 5 additions & 0 deletions src/views/Home/requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

// eslint-disable-next-line import/prefer-default-export
export function getHomeTitle() {
return 'Running divar-starter-kit successfully.';
}

0 comments on commit e5ba256

Please sign in to comment.