Skip to content

Commit f9a10f2

Browse files
committed
add webapck support for arrow functions in class syntax
1 parent 6b94d0a commit f9a10f2

File tree

5 files changed

+66
-31
lines changed

5 files changed

+66
-31
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"plugins": [
3+
"transform-class-properties"
4+
]
5+
}

frontend/components/modal/modal.jsx

+38-30
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
import React from 'react'
22
import ModalLoginForm from './modal_login_form'
33
import ModalSignupForm from './modal_signup_form'
4+
import { withRouter } from 'react-router-dom'
45

5-
const Modal = ({
6-
reveal, errors, login, signup, hide, revealModalSignup, revealModalLogin}) => {
6+
class Modal extends React.Component {
77

8-
const classes = reveal ? 'modal' : 'modal hide'
9-
let modal = <div></div>
8+
handleHide = event => {
9+
debugger
10+
this.props.history.push('/')
11+
this.props.hide()
12+
}
1013

11-
if (reveal === 'login') {
12-
modal = <ModalLoginForm
13-
title="Log In"
14-
errors={errors}
15-
submitAction={login}
16-
hide={hide}
17-
revealModalSignup={revealModalSignup} />
14+
render () {
15+
const classes = this.props.reveal ? 'modal' : 'modal hide'
16+
let modal = <div></div>
1817

19-
} else if (reveal) {
20-
modal = <ModalSignupForm
21-
title="Sign Up"
22-
errors={errors}
23-
submitAction={signup}
24-
hide={hide}
25-
revealModalLogin={revealModalLogin} />
26-
}
18+
if (this.props.reveal === 'login') {
19+
modal = <ModalLoginForm
20+
title="Log In"
21+
errors={this.props.errors}
22+
submitAction={this.props.login}
23+
hide={this.props.hide}
24+
revealModalSignup={this.props.revealModalSignup} />
2725

28-
return (
29-
<div className={classes}>
30-
<div className="modal-content">
31-
<button
32-
onClick={hide}
33-
className="modal-close-button">
34-
x
26+
} else if (this.props.reveal) {
27+
modal = <ModalSignupForm
28+
title="Sign Up"
29+
errors={this.props.errors}
30+
submitAction={this.props.signup}
31+
hide={this.props.hide}
32+
revealModalLogin={this.props.revealModalLogin} />
33+
}
34+
35+
return (
36+
<div className={classes}>
37+
<div className="modal-content">
38+
<button
39+
onClick={this.handleHide}
40+
className="modal-close-button">
41+
x
3542
</button>
3643

37-
{modal}
44+
{modal}
45+
</div>
3846
</div>
39-
</div>
40-
)
47+
)
48+
}
4149
}
42-
export default Modal
50+
export default withRouter(Modal)

package-lock.json

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
"redux-thunk": "^2.3.0",
4444
"webpack": "^4.15.1",
4545
"webpack-cli": "^3.0.8"
46+
},
47+
"devDependencies": {
48+
"babel-plugin-transform-class-properties": "^6.24.1"
4649
}
4750
}

webpack.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = {
1414
use: {
1515
loader: 'babel-loader',
1616
query: {
17-
presets: ['env', 'react']
17+
presets: ['env', 'react'],
18+
plugins: ["transform-class-properties"]
1819
}
1920
},
2021
}

0 commit comments

Comments
 (0)