如何向 firestore 添加不同的 <text>?

How to add different <text> to firestore?

我正在尝试向 firestore 文档发送一些文本,但它没有发送任何问题。

请参考图片部分代码:https://ibb.co/dL0V0yv

但是我有几个按钮,我想以这样的方式设置我的代码,以便每个 onPress 都会发送不同的文本。我可以通过手动重写具有 diffenet 状态的 generateDoc 函数来实现这一点,但我想知道我如何通过复制来做到这一点?使用功能道具做一些事情,以便可以在 onPress 内更改文本,但我不知道如何生成它。请帮忙。

给函数一个参数,像这样...

generateDoc = taskName => {
  return firestore().collection('Rooms')... // OP code here
    .set({ Task: taskName }).then...
}

然后这样称呼它...

onPress={this.generateDoc('task name for this button')}

编辑

要在 Press 上调用两个或更多函数,最好保持模板代码干净并将两个 promise 返回函数合并为一个,如下所示...

operationA = param => {
  return firestore()...   // be sure to return the promise
}

operationB = param => {
  return firestore()...   // same thing here, return the promise
}

operationAandB = (paramA, paramB) => {
  // if the A and B are independent, then do them together
  return Promise.all([ operationA(paramA), operationB(paramB) ])

  // or if A and B must run in sequence, then
  return operationA(paramA).then(() => operationB(paramB))
}

onPress={this.operationAandB('paramA', 'paramB')}