这是我调用函数的方式
newPost({
post: this.props.post,
files: this.props.files,
}, someOtherVariables)
函数:
newPost: async ({ post, files }, someOtherVariables) => {
return upload(`/services/share/post/new`, post, files, someOtherVariables)
}
自从我升级到React Native 0.59.1以来,我一直收到“发布为只读”错误。尽管单击调试日志中的错误会将我重定向到该函数的声明,但是甚至没有调用该函数,并且通过在函数的第一行添加console.log()comand对其进行了测试。 / p>
post并未声明为const,并且其内容甚至在函数或调用函数的行中都没有改变。为什么会出现此错误?
package.json:
"react": "16.8.0",
"react-native": "~0.59.1",
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-jest": "^24.9.0",
"babel-plugin-module-resolver": "^3.2.0",
"metro-react-native-babel-preset": "^0.56.0",
"jest": "^24.9.0",
我稍微缩短了代码以提高可读性。我将保留下面的整个代码,以防查看整个代码有帮助。
send() {
if (this.fileSelected() && this.detailFilled() && this.groupSelected()) {
this.setSending(true)
let service = this.props.isUpdating ? PostService.updatePost : PostService.newPost
service({
post: this.props.post.type === 'CLOSE' ? { ...this.props.post, type: 'TEXT' } : this.props.post,
files: this.props.files,
}, progress => {
this.setState({ progress })
}).then(res => {
this.setSending(false)
}).catch(err => {
console.log(err)
})
}
}
newPost: async ({ post, files }, onProgress) => {
let formData = new FormData();
onProgress(0);
if (post.type === 'VIDEO') {
post.video = await vimeoUpload(files[0], onProgress).catch(Promise.reject)
} else {
files.forEach(file => {
file.name = encodeURIComponent(file.name)
formData.append("files", file)
})
}
formData.append("post", JSON.stringify(post))
return upload(`/services/share/post/new`, formData, onProgress)
},