javascript - Reactjs - how to handle keys correctly in reused components -


I have recently started with Reactjs and I find it really interesting. The keys are about identity, so the way to identify each component through a unique key is correct, right? Suppose I have this example:

  var fruit = [['fruit id': 351421, 'fruit': 'ban'], {'fruit id': 254134, 'fruit': 'Apple'}, {'fruit id': 821553, 'fruit': 'orange'}]; reaction. DOM.ul (tap, fruit.mape (work (commodity) (return.dom.link ({key: item.foot id}, item.fert));}));   

See the large ID number. Now, my question is, is it better to use numbers such as IDs or strings like IDs?

Thank you!

It really does not matter, the only thing is that the important thing is that the original parent Within the element is unique among the siblings.

Usually for simple recycling on elements such as or & lt; Options & gt; This is OK to use the index inside your errator.

EG:

  var option = []; (Var i = 0; i & lt; this.props.options.length; i ++) {var option = this.props.options [i]; Options.push (& lt; Option key = {i} value = {option.value} & gt; {option.name} & lt; / options & gt;); }   

Once it does not work well, then you are adding / removing key elements in different commands, so that later your key is with another brother. Could fight In that situation, you want to generate a key in another way to ensure that it is unique - or use specific keys known from your model, whatever way you do it, as long as it is between her siblings It will be unique, it will be fine.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -