Skip to content

Instantly share code, notes, and snippets.

@talentlessguy
Created December 29, 2018 18:07
Show Gist options
  • Save talentlessguy/901a4f55acf7ea843dc9c47b02326c25 to your computer and use it in GitHub Desktop.
Save talentlessguy/901a4f55acf7ea843dc9c47b02326c25 to your computer and use it in GitHub Desktop.
JSON isn't parsed :(
const app = require('express')()
app.use(require('cors')())
app.get('/verycoolguy/posts/1', (req,res) => {
res.sendFile(__dirname + '/post.json')
})
app.listen(4000)
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>
)
}
{
"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