Reactjs: Key undefined when accessed as a prop

前端 未结 3 854
抹茶落季
抹茶落季 2020-12-31 06:19

Tools: Reactjs 0.14.0 Vanilla Flux

I need unique identifiers for 2 reasons:

  1. Child Reconciliation
  2. Keeping track of what child
3条回答
  •  情话喂你
    2020-12-31 07:01

    As we already established in other answers that you can't use key since it isn't passed as a prop and instead used internally by react. Here is my 2 cents as an alternative:
    Since you're passing the entire array of messages as a prop while creating the component, you don't necessarily need to pass another prop with id. You can simply use {this.props.message.id} whenever you need to use id.

提交回复
热议问题