spring-attic / tut-react-and-spring-data-rest

React.js and Spring Data REST :: A tutorial based on the 5-part blog series by Greg Turnquist
https://spring.io/guides/tutorials/react-and-spring-data-rest
882 stars 1.58k forks source link

Part 3 app.js UpdateDialog input key issue #50

Open jamesyin96 opened 7 years ago

jamesyin96 commented 7 years ago

Hi,

Thanks for this awesome tutorial. I learned good react design here. But I do find a place that could be better.

It's in Part 3 - Conditional Operations. In UpdateDialog component, when we define the form input, we set

<p key={this.props.employee.entity[attribute]}>

This works most of the time, but it can't guarantee the key uniqueness. If firstName = lastName, we will have a problem. If we set

<p key={attribute}>

It can solve this problem because attributes are different by design. I notice we use this key assignment in CreateDialog component. So UpdateDialog component should follow the same pattern, right?

Thanks

gregturn commented 7 years ago

Well, the ideal key would be a "self" link URI.

jamesyin96 commented 7 years ago

Yes, that's even better. :)

gregturn commented 7 years ago

Pull request welcome. Just be sure to hit each section. :)