Skip to content

Instantly share code, notes, and snippets.

@talentlessguy
Last active January 1, 2019 15:34
Show Gist options
  • Save talentlessguy/91decc23ca31b564169b15908e81991c to your computer and use it in GitHub Desktop.
Save talentlessguy/91decc23ca31b564169b15908e81991c to your computer and use it in GitHub Desktop.
Weird stuff with parcel and babel
import React from 'react'
import { hydrate } from 'react-dom'
import Post from './Post'
hydrate(
<div>
<Post/>
</div>, document.getElementById('root')
)
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')
.catch(e => console.error(e))
.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>
)
}
{
"presets": ["env", "react"]
}
$ yarn start
yarn run v1.12.3
$ parcel public/index.html --port 3000
Server running at http://localhost:3000
× \src\Post.js:28:11: /src/Post.js: Unexpected token (28:11)
26 | })
27 | }>
28 | render = () => (
| ^
29 | <div>
30 | <Img src={this.state.image}/>
31 | <ReactMarkdown source={this.state.text}/>
{
"name": "demo-newsfeed",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-markdown": "^4.0.4"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"parcel-bundler": "^1.11.0"
},
"scripts": {
"start": "parcel public/index.html --port 3000"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment