我在使用 redux 表单时遇到错误。它说我的文件名“搜索只能读取”。这是 redux 表单问题还是其他问题?跟连接有关系吗?现在我只能对表单使用旧的方式
import React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
var Select = require('react-select');
import {fetchAllEmails, searchUsers} from '../actions/searchAction';
import {getDashBoardDataFromEmail, clearUserState} from '../actions/dashboardAction';
var LocalToken = localStorage.getItem('token');
import _ from 'lodash';
import {reduxForm} from 'redux-form';
const Search = React.createClass({
contextTypes:{
router: React.PropTypes.object.isRequired
},
getInitialState: function(){
return {
value:'xyz'
}
},
componentWillMount: function(){
this.props.fetchAllEmails(LocalToken);
},
handleChange: function(e){
this.props.getDashBoardDataFromEmail(LocalToken,e)
this.context.router.push('/dashboard')
},
handleSearchChange(e) {
this.setState({ value: e.target.value });
},
handleInputSubmit(){
console.log('hello')
},
render(){
const {fields: {someFormField, handleInputSubmit} }= this.props;
return(
<div>
<h3 style={{textAlign:'center',color:'#b4b7c1'}}>Search</h3>
<h6>Search for something</h6>
<form onSubmit={this.handleInputSubmit}>
<div>
<input type="text" placeholder="Search By ..." {...someFormField} />
</div>
</form>
</div>)
}
})
Search = reduxForm({
form:'Search',
fields:['someFormField']
})(Search)
function mapStateToProps({ search,dashboardData,tokenValue }) {
return { search, dashboardData, tokenValue }
}
//functions from action
function mapDispatchToProps(dispatch){return bindActionCreators({fetchAllEmails, searchUsers, getDashBoardDataFromEmail, clearUserState},dispatch)}
export default connect(mapStateToProps, mapDispatchToProps)(Search);