Skip to content

Commit 68c0354

Browse files
committed
add App component with ParallaxProvider, update server to use server side rendering
1 parent 4debfe0 commit 68c0354

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

example/client.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import 'babel-polyfill';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4-
import { ParallaxTest } from 'components';
5-
import { ParallaxController } from 'react-scroll-parallax';
6-
7-
ParallaxController.init();
4+
import { App } from 'components';
85

96
const root = document.getElementById('root');
107

11-
ReactDOM.render(<ParallaxTest />, root);
8+
ReactDOM.render(<App />, root);

example/components/App/App.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, { Component } from 'react';
2+
// import PropTypes from 'prop-types';
3+
import { ParallaxProvider } from 'react-scroll-parallax';
4+
import { ParallaxTest } from 'components';
5+
6+
export default class App extends Component {
7+
render() {
8+
return (
9+
<ParallaxProvider>
10+
<ParallaxTest />
11+
</ParallaxProvider>
12+
);
13+
}
14+
}

example/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export ParallaxTest from './ParallaxTest/ParallaxTest.js';
2+
export App from './App/App.js';

example/server.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ import express from 'express';
44

55
import React from 'react';
66
import ReactServer from 'react-dom/server';
7-
import { ParallaxTest } from 'components';
7+
import { App } from 'components';
88

99
import 'babel-polyfill';
1010

11-
const app = express();
11+
const server = express();
1212

13-
app.use('/static', express.static(path.resolve(__dirname, './dist')));
13+
server.use('/static', express.static(path.resolve(__dirname, './dist')));
1414

15-
app.get('*', (req, res) => {
15+
server.get('*', (req, res) => {
1616
const html = fs
1717
.readFileSync(path.resolve(__dirname, './index.html'))
1818
.toString();
19-
const markup = ReactServer.renderToString(<ParallaxTest />);
19+
20+
const markup = ReactServer.renderToString(<App />);
2021

2122
res.send(html.replace('$react', markup));
2223
});
2324

24-
app.listen(3000, () => {
25+
server.listen(3000, () => {
2526
console.log('Listening on: http://localhost:3000');
2627
});

0 commit comments

Comments
 (0)