Created
December 29, 2018 18:07
-
-
Save talentlessguy/901a4f55acf7ea843dc9c47b02326c25 to your computer and use it in GitHub Desktop.
JSON isn't parsed :(
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.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, { Component } from 'react' | |
import axios from 'axios' | |
import ReactMarkdown from 'react-markdown' | |
export default class Post extends Component { | |
constructor () { | |
super() | |
this.state = {} | |
} | |
componentDidMount(){ | |
axios.get('http://localhost:4000/verycoolguy/posts/1') | |
.then(res => this.setState({ | |
content: res.data.content, | |
likes: res.data.likes, | |
comments: JSON.stringify(res.data.comments) | |
})) | |
} | |
render = () => ( | |
<div> | |
<ReactMarkdown source={this.state.content}/> | |
<span>Likes: {this.state.likes}</span> | |
<div className="comments"> | |
{JSON.parse(this.state.comments)} | |
</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
{ | |
"content": "**bold**", | |
"likes": "30", | |
"comments": { | |
"supadupauser": { | |
"content": "md rocks", | |
"likes": "10", | |
"branch": "origin" | |
}, | |
"anothercooluser": { | |
"content": "md sucks", | |
"likes": "0", | |
"branch": "supadupauser" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment