javascript - How to create react components so that each component has a unique id -


i want tract components id, want ensure each component of class have unique id.

should use higher order components?

or create factory function:

nextid = 1; function componentfactory(props) {   return (     <component id={nextid++} {...props}/>   ); } 

this approach not pretty because can't use <> angle brackets create component.

my use case is:

  • i have list of todos each todo should placed on specific coordinate.

  • a todolist component holds state of coordinates each todo item associating coordinate todo id.

  • later want add new todo, update store add new todo.

  • todolist component looks id of each todo item , finds specific coordinate item.

  • if can't find coordinate id, randomly assigns new coordinate.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -