我正在使用反應(yīng)+redux。我有一個(gè)帶有數(shù)據(jù)和圖像的模態(tài)表單,成功后我需要關(guān)閉從 redux 返回的模態(tài)否則顯示錯(cuò)誤。在調(diào)度函數(shù)中,我還有 1 個(gè)回調(diào)函數(shù)來將圖像存儲(chǔ)到 S3。我正在從 redux-thunk 返回承諾,但我不斷收到“TypeError:無法讀取未定義的屬性 'then'”。零件handleSubmit = e => { e.preventDefault(); if(this.isFieldEmpty()){ this.setState({ message: "All fields are mandatory with at least 1 pic" }); return; } else { this.setState({ message: "" }); } const data = { name: this.state.name, description : this.state.description, points : this.state.points, attributes : this.state.attributes, images : this.state.images, created_by: localStorage.getItem('id'), } this.props.createItem(data).then(() => { this.hideModal(); }) }const mapDispatchToProps = dispatch => { return { createItem: data => { return dispatch(createItem(data)) }, };};行動(dòng)const saveItemImages = (images,successcb, failurecb) => { if(images.length > 0){ const formData = new FormData(); for(var x = 0; x<images.length; x++) { formData.append('image', images[x]) } const token = localStorage.getItem('token'); fetch(`${backendUrl}/upload/item-images/`, { method: "POST", headers: { 'Authorization': `Bearer ${token}` }, credentials: 'include', body: formData }) .then(res => { if(res.status === 200){ res.json().then(resData => { successcb(resData.imagesUrl); }); }else{ res.json().then(resData => { failurecb(resData.message); }) } }) .catch(err => { console.log(err); }); } else { successcb([]); }}
React Redux Thunk 回調(diào)到另一個(gè)函數(shù)——TypeError:
SMILET
2022-06-09 11:15:45