入力を含むReactコンポーネントがあります。コンポーネントはAPIを呼び出すreduxアクションを送出します。コンポーネントごとに "SUCCESS"メッセージを表示したいのですが、減速機以外の方法でメッセージを取得する方法はありませんか?しかし、私が減速機でそれをやろうとしたら、それはフォームのコンポーネントをすべて更新する一般的なメッセージに過ぎませんでしたか?還元反応の結果に応じてReactコンポーネントを更新する方法
// COMPONENT
export default class Stock extends React.Component {
constructor(props) {
super(props);
this.state = {
value: "",
id: this.props.hit['Name of Item'],
}
}
handleChange(e){
e.preventDefault();
this.setState({value: e.target.value});
}
handleClick(e){
e.preventDefault();
this.props.dispatch(updatePosStock(this.state.value, this.state.id));
}
render() {
return (
<div className="item">
<p>{this.props.hit['Name of Item']}: {this.props.hit.Quantity}</p>
<p>Stock ID: {this.props.hit.objectID}</p>
<div className="control">
<input className="input" value={this.state.value} type="text" onChange={this.handleChange.bind(this)} />
<a href="" onClick={this.handleClick.bind(this)} >save</a>
//MESSAGE TO DISPLAY HERE DEPENDING ON handleClick
</div>
</div>
)
}
}
// ACTION
export function updatePosStock(product, stock){
return function(dispatch) {
axios.post('/api/v1/product/', {
product,
stock
})
.then((response) => {
//console.log(response.data);
return response.data;
//dispatch({type: 'FETCH_PRODUCT_FULFILLED', payload: response.data})
})
.catch((error) => {
console.log(error);
})
}
}
おかげで、はい、あなたがその場でコンセプトを持って、私はこの行くあげますよ。この種のことは、私の年齢を悩ませてきました! – jhodgson4