Last active
December 30, 2015 19:26
-
-
Save mohebifar/d22bd3bf123f57367c83 to your computer and use it in GitHub Desktop.
Redux-form issue #485
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 config = { | |
"presets": ["react", "es2015", "stage-0"] | |
}; | |
require('babel-core/register')(config); | |
require('./test'); |
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
{ | |
"name": "test-redux-form-485", | |
"version": "0.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"babel-core": "^6.3.26", | |
"babel-preset-es2015": "^6.3.13", | |
"babel-preset-react": "^6.3.13", | |
"babel-preset-stage-0": "^6.3.13", | |
"react": "^0.14.5", | |
"react-dom": "^0.14.5", | |
"react-redux": "^4.0.6", | |
"redux": "^3.0.5", | |
"redux-form": "^4.0.7" | |
} | |
} |
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 ReactDOM from 'react-dom/server'; | |
import { createStore, combineReducers } from 'redux'; | |
import { Provider } from 'react-redux'; | |
import { reducer as formReducer, reduxForm } from 'redux-form'; | |
const reducer = combineReducers({form: formReducer}); | |
const store = createStore(reducer); | |
class TestComponent extends Component { | |
render() { | |
const initialValues = { | |
array: ['a', 'b'], | |
nonArray: 'hello' | |
}; | |
return <Form initialValues={initialValues}/>; | |
} | |
} | |
class Form extends Component { | |
render() { | |
const {fields: {array, nonArray}} = this.props; | |
console.log('["a", "b"] is expected, real value: ', array); | |
console.log('"hello" is expected, real value: ', nonArray.defaultValue); | |
return <div> | |
<input type="text" {...nonArray}/> | |
{array.map(ticket => <input type="text" {...ticket}/>)} | |
</div>; | |
} | |
} | |
Form = reduxForm({ | |
form: 'test', | |
fields: ['array[]', 'nonArray'] | |
})(Form); | |
const renderedDom = ReactDOM.renderToString(<Provider store={store}> | |
<TestComponent /> | |
</Provider>); | |
console.log(renderedDom); | |
// Output (data-react-id s are pulled out) | |
// | |
// ["a", "b"] is expected, real value: [] | |
// "hello" is expected, real value: hello | |
// <div><input type="text" name="nonArray" value="hello"/></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment