我在组件中有一些状态,我想传递给React.js中的动作 。我怎样才能做到这一点?如何将状态传递给React.js中的操作?
mycomponent.js
cityHandleUpdateInput() {
this.setState({
city: this.refs.city.refs.searchTextField.input.value
})
const { city } = this.state;
this.props.fetchResCity(city)
}
myaction.js
export const fetchResCity = (city) => (dispatch, getState) => {
if (!getState().resCity.isFetching) {
console.log(getState().city)
console.log(city)
const endpoint = 'rescity?city=${city}';
dispatch({
[CALL_API]: {
types: [ RES_CITY_REQUEST, RES_CITY_SUCCESS, RES_CITY_FAILURE ],
endpoint: endpoint
}
})
}
}
它不工作。我的代码有问题吗? 当我在我的动作中记录城市变量时,它只是undefined
。
它是否正确登录cityHandleUpdateInput –
我认为setState需要时间来更新状态。你能否在fetchCity函数中传递'this.refs.city.refs.searchTextField.input.value' –