Created
December 30, 2018 12:30
-
-
Save talentlessguy/8f4f1b245846b8f837f735f273e9fb0b to your computer and use it in GitHub Desktop.
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
const app = require('express')() | |
app.use(require('cors')()) | |
app.get('/verycoolguy/posts/1', | |
(req, res) => res.sendFile(__dirname + '/post.json') | |
) | |
app.get('/cdn/verycoolguy/posts/1/img.jpg', | |
(req, res) => res.sendFile(__dirname + '/img.jpg')) | |
app.listen(4000) |
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 { hydrate } from 'react-dom' | |
import Post from './Post' | |
hydrate( | |
<div> | |
<Post/> | |
</div>, 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, { Component } from 'react' | |
import axios from 'axios' | |
import ReactMarkdown from 'react-markdown' | |
import Img from 'react-image' | |
export default class Post extends Component { | |
constructor () { | |
super() | |
this.state = { | |
content: '', | |
likes: '', | |
comments: [] | |
} | |
} | |
componentDidMount(){ | |
axios.get('http://localhost:4000/verycoolguy/posts/1') | |
.then(res => { | |
this.setState({ | |
text: res.data.text, | |
likes: res.data.likes, | |
comments: res.data.comments, | |
image: res.data.image | |
}); | |
console.log(this.state.image) | |
}) | |
} | |
render = () => ( | |
<div> | |
<Img src={this.state.image}/> | |
<ReactMarkdown source={this.state.text}/> | |
<span>Likes: {this.state.likes}</span> | |
<div className="comments"> | |
{this.state.comments.map(e => ( | |
<div> | |
<p><b>{e.author}</b> {e.text}</p> | |
</div> | |
))} | |
</div> | |
</div> | |
) | |
} |
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
{ | |
"image": "localhost:4000/cdn/verycoolguy/posts/1/img.jpg", | |
"text": "**bold**", | |
"likes": "30", | |
"comments": [ | |
{ | |
"author": "supadupasuser", | |
"text": "md rocks", | |
"likes": "10" | |
}, | |
{ | |
"author": "anothercooluser", | |
"text": "html is better", | |
"likes": "0" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment