This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Home.js | |
import React from 'react'; | |
class Home extends React.Component { | |
render() { | |
return <p>Home</p>; | |
} | |
} | |
export default Home; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ create-react-app static-react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
+import { BrowserRouter, Link, Switch, Route } from 'react-router-dom'; | |
+import Home from './Home'; | |
+import Post from './Post'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
class App extends Component { | |
render() { | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: node_js | |
node_js: | |
- "node" | |
cache: | |
- yarn | |
install: | |
- yarn install | |
script: | |
- yarn build | |
deploy: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
}, | |
"scripts": { | |
"start": "react-scripts start", | |
"build": "react-scripts build", | |
+ "postbuild": "react-snap", | |
"test": "react-scripts test --env=jsdom", | |
"eject": "react-scripts eject" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
-import ReactDOM from 'react-dom'; | |
+import { hydrate, render } from 'react-dom'; | |
import './index.css'; | |
import App from './App'; | |
-import registerServiceWorker from './registerServiceWorker'; | |
-ReactDOM.render(<App />, document.getElementById('root')); | |
-registerServiceWorker(); | |
+const rootElement = document.getElementById('root'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
+import { createClient } from 'contentful'; | |
class Home extends React.Component { | |
+ state = { | |
+ posts: [] | |
+ }; | |
+ | |
+ componentWillMount() { | |
+ const client = createClient({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { createClient } from 'contentful'; | |
class Home extends React.Component { | |
state = { | |
posts: [] | |
}; | |
componentWillMount() { | |
const client = createClient({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
+import { Link } from 'react-router-dom'; | |
import { createClient } from 'contentful'; | |
class Home extends React.Component { | |
return this.state.posts.map(post => { | |
console.log(post); | |
- return <p>Post</p>; | |
+ return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 className="App-title">Welcome to React</h1> | |
- <Link to="/">Home</Link> <Link to="/post/">Post</Link> | |
</header> | |
<Switch> | |
<Route exact path="/" component={Home} /> | |
- <Route path="/post/" component={Post} /> | |
+ <Route path="/post/:id" component={Post} /> | |
</Switch> | |
</div> | |
</BrowserRouter> |