我正在尝试将分派函数的响应传递回我的组件代码。我从后端收到签名请求,然后从组件上载文件。
这里的组件代码从后端获得S3签名以上传文件
handleSubmitClick = async () => {
if (this.state.name){
let newFile = {
filename: this.state.name,
filetype: this.state.media.type,
}
this.props.signS3(newFile.filename, newFile.filetype)
.then( res => console.log('NO RESPONSE', res))
this.handleCloseClick();
} else {
this.setState({ inputError: true });
}
}
我从mapdispatchtoprops获得了signS3
const mapDispatchToProps = dispatch => {
return {
handleCancelClick() {
dispatch(openAttachAssetModal(false));
},
signS3(filename, filetype) {
dispatch(signS3(filename, filetype));
}
}
}
运行我的突变
export function signS3(filename, filetype) {
return function thunk(dispatch) {
const client = ApolloClient();
return client.mutate({
variables: { filename, filetype },
mutation: gql`
mutation signS3($filename: String!, $filetype: String!){
signS3(input: {
filename: $filename
filetype: $filetype
}) {
signedRequest
url
}
}
`
})
.then(response => {
return response
})
}
}
除了我没有收到回复...
答案 0 :(得分:1)
在mapDispatchToProps
中,您必须返回在signS3
中调度的内容(在这种情况下为承诺),否则该值将是不确定的。
// ...
signS3(filename, filetype) {
return dispatch(signS3(filename, filetype));
}