Skip to content

Commit a5c4ab6

Browse files
committed
Add webpack-dev-server to allow us to visualize form
1 parent 0f1cb21 commit a5c4ab6

7 files changed

+75
-5
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["es2015", "react"]
2+
"presets": ["es2015", "react"],
3+
"plugins": ["react-hot-loader/babel"]
34
}

app/ContactFormComponent.jsx renamed to app/ContactFormComponent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class ContactForm extends Component {
1414

1515
return (
1616
<form onSubmit={this.props.handleSubmit(this.mySubmit.bind(this))}>
17+
<h1>Contact Form</h1>
1718
<label>First name</label>
19+
{' '}
1820
<input {...firstName}/>
19-
{firstName.touched && firstName.error && <div className='help-block'>{firstName.error}</div>}
21+
{' '}
22+
{firstName.touched && firstName.error && <span className='help-block'>{firstName.error}</span>}
23+
<p></p>
2024
<button type="submit">
2125
<i className={submitClassName}/> Submit
2226
</button>

app/ContactFormContainer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import React from 'react'
2+
import { connect } from 'react-redux'
23
import ContactFormComponent from './ContactFormComponent'
34
import { reduxForm } from 'redux-form'
45
import * as formValidations from './formValidations'
56

6-
const ContactFormContainer = reduxForm({
7+
let ContactFormContainer = reduxForm({
78
form: 'contact',
89
fields: ['firstName'],
910
validate: formValidations.createValidator({
1011
firstName: formValidations.required
1112
})
1213
})(ContactFormComponent)
1314

15+
const mapStateToProps = null
16+
const mapDispatchToProps = {
17+
// Note: we aren't actually doing anything with this. The ContactForm component has a propType, so I'm showing where it might come from.
18+
onSave: contactFormValues => { return { type: 'FORM_SUBMIT', payload: contactFormValues } }
19+
}
20+
21+
ContactFormContainer = connect(mapStateToProps, mapDispatchToProps)(ContactFormContainer)
22+
1423
export default ContactFormContainer

app/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
import { render } from 'react-dom'
3+
import { createStore, combineReducers } from 'redux'
4+
import { Provider } from 'react-redux'
5+
import { reducer as reduxFormReducer } from 'redux-form'
6+
import ContactFormContainer from './ContactFormContainer'
7+
8+
const rootReducer = combineReducers({
9+
form: reduxFormReducer
10+
})
11+
const store = createStore(rootReducer, window.devToolsExtension && window.devToolsExtension())
12+
13+
render(
14+
<Provider store={store}>
15+
<ContactFormContainer/>
16+
</Provider>,
17+
document.getElementById('root')
18+
)

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>redux-form-test</title>
5+
<style>
6+
.help-block {
7+
color: red;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
<div id="root"></div>
13+
<script src="bundle.js"></script>
14+
</body>
15+
</html>

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Showing some unit and integration tests for redux-form",
55
"keywords": [],
66
"scripts": {
7-
"webpack": "node_modules/.bin/webpack",
7+
"dev": "node_modules/.bin/webpack-dev-server",
88
"test": "node_modules/.bin/mocha -w --compilers js:babel-core/register tests/*"
99
},
1010
"devDependencies": {
@@ -19,11 +19,13 @@
1919
"mocha": "^2.4.5",
2020
"react-addons-test-utils": "^15.0.2",
2121
"sinon": "^1.17.4",
22-
"webpack": "^1.13.0"
22+
"webpack": "^1.13.0",
23+
"webpack-dev-server": "^1.15.1"
2324
},
2425
"dependencies": {
2526
"react": "^15.0.2",
2627
"react-dom": "^15.0.2",
28+
"react-hot-loader": "^3.0.0-beta.3",
2729
"react-redux": "^4.4.5",
2830
"redux": "^3.5.2",
2931
"redux-form": "^5.2.3"

webpack.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const webpack = require('webpack')
2+
3+
module.exports = {
4+
entry: {
5+
app: './app/index.js'
6+
},
7+
module: {
8+
loaders: [
9+
{ pattern: /\.jsx?/, loader: 'babel', exclude: /node_modules/ }
10+
]
11+
},
12+
plugins: [new webpack.HotModuleReplacementPlugin({ })],
13+
devServer: {
14+
historyApiFallback: true,
15+
hot: true,
16+
stats: {
17+
colors: true,
18+
chunks: false
19+
}
20+
},
21+
}

0 commit comments

Comments
 (0)