I'm adding a document to a firestore collection (inboxItems
) onSubmit
of a form.
onCreateInboxItem = event => {
this.props.firebase.inboxItems().add({
name: this.state.newInboxItemName,
created: '', // I need a timestamp field here
})
this.setState({ name: '' });
event.preventDefault();
}
How do I get the created
field to be a timestamp field, with current timestamp as a value? It would need to be consistent across users and timezones.
I see firebase.firestore.FieldValue.serverTimestamp()
mentioned in the firebase docs, but at this point the field value isn't set yet. I would like to avoid an extra operation to update the field.