第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

React Redux Thunk 回調(diào)到另一個(gè)函數(shù)——TypeError:

React Redux Thunk 回調(diào)到另一個(gè)函數(shù)——TypeError:

SMILET 2022-06-09 11:15:45
我正在使用反應(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([]);    }}
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

您應(yīng)該返回 aPromise為這樣的操作創(chuàng)建異步流:


export const createItem = data => dispatch => new Promise((resolve, reject) => {


  // do something was a success

  resolve();


  // do something was a fail

  reject();


});


查看完整回答
反對(duì) 回復(fù) 2022-06-09
  • 1 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)