【发布时间】:2019-11-29 20:42:04
【问题描述】:
我正在尝试在 redux-thunk 的帮助下将图像发送到 firebase 商店。没有 redux,代码可以完美运行。
已编辑:这是错误的 thunk ./src/Thunks/index.js
// uploadReducer Thunk
import {uploadImagesPending, uploadImagesProgress, uploadImagesSuccess, uploadImagesError} from '../Actions';
import fire, { auth } from '../fire';
// import store from '../index';
function uploadImages(images) {
return dispatch => {
dispatch(uploadImagesPending());
// const images = store.getState().images;
const userID = fire.auth().currentUser.uid;
const uploadTask = fire.storage().ref(`users/${userID}`).child(`images/${images.name}`).put(images);
uploadTask.on('state changed', (snapshot) => {
const progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
dispatch(uploadImagesProgress(progress))
}),
(error) => {
dispatch(uploadImagesError(error))
},
() => {
fire.storage().ref('images').child(images.name).getDownloadURL().then(url => {
dispatch(uploadImagesSuccess(url))
})
}
}
}
export default uploadImages;
简单的动作和reducer...
图片来自上传组件
handleChange(event) {
if(event.target.files[0]) {
const targetImages = event.target.files[0];
this.setState({
images: targetImages
});
}
}
uploadImage() {
const { uploadImages } = this.props;
const { images } = this.state;
uploadImages(images);
}
但抓住
编译失败。 ./src/Thunks/index.js 第 17 行:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions 搜索关键字以详细了解每个错误。
【问题讨论】:
-
请发此文件
/src/Thunks/index.js。 -
嗨!就是 /src/Thunks/index.js )
标签: firebase react-redux redux-thunk