1
我很困惑道具或状态在这里使用。如果我在@connect中使用状态,我会收到错误并且不起作用。当我使用道具时,它不能与onchange处理程序一起设置新的道具。请帮助我如何使用状态或道具进行输入工作。我正在从api中检索初始数据。我们应该使用状态还是道具来处理投入反应?
import React, {PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import { asyncConnect } from 'redux-async-connect';
import {load, isLoaded} from 'redux/modules/overview';
@asyncConnect([{
promise: ({ store: { dispatch, getState }, params: { id }, }) => {
const promises = [];
if (!isLoaded(getState())) {
promises.push(dispatch(load(id)));
}
return Promise.all(promises);
}
}])
@connect(
state => ({
overview: state.overview.data
}),
dispatch => bindActionCreators({load}, dispatch))
export default class Overview extends React.Component {
changeinput1(e) {
this.props.overview.title = e.target.value;
// changing value does not work here
}
constructor (props) {
super();
this.state = {
overview: null,
}
}
render() {
return (
<div>
<label>Input 1</label>
<input type="text" className="form-control" id="title" name="title" maxlength="35" value={this.props.overview.title} onChange={this.changeinput1.bind(this)}/>
</div>
)
}
}
我也想做验证,并希望保存onBlur的输入值,所以我不想使用窗体。
我想获取组件状态中的缩减器值,但无法使用@connect –
获取类似于@connect( state =>(this.state.overview:state.overview.data }), dispatch => bindActionCreators({load},dispatch))我想要在组件的状态概述来操纵它在输入 –
你应该得到组件的道具的redux状态,像this.props。概述... – shixukai