我有 Action 组件,我在其中添加新projects
组件firestore.collection
export const createProject = (project) => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const firestore = getFirestore();
firestore.collection('projects').add({
...project
}).then(() => {
dispatch({})
}).catch((err) => {
dispatch({});
})
}
};
我有组件:
state = {
title: '',
content: '',
file: ''
}
handleChange = (e) => {
this.setState({
[e.target.id] : e.target.value
})
}
handleOnFileChange = (e) => {
let file = e.target.files[0];
this.setState({
[e.target.id] : file
})
}
handleSubmit = (e) => {
e.preventDefault();
console.log(this.state)
}
<form onSubmit={this.handleSubmit}>
<input type="text" id="title" onChange={this.handleOnFileChange}/>
<textarea id="content" onChange={this.handleChange}></textarea>
<input type="file" id="file" onChange={this.handleChange}/>
</form>
const mapDispatchToProps = (dispatch) => {
return {
createProject: (project) => dispatch(createProject(project))
}
}
提交后我收到此错误:דFirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: a custom File object (found in field file)”
file
如果我从中删除state
,并尝试进入add
该状态,没有file
,一切正常,我的项目正在添加firestore.collection
,但我需要firestore.collection
从状态(title
和content
)file
添加到所有内容