tocodeil / react-course-examples

React course examples
1 stars 22 forks source link

ToCode Solution: תרגול פקדים מורכבים #32

Closed wmashal closed 6 years ago

wmashal commented 6 years ago

I still have problem with the text fields where we update units 1- add 3 items in the list 2- try to update the unit in the first row , (not works)

this becuase the ref={unitsNo => { this.unitsNo = unitsNo }} always works with the last text filed in the table what u suggest to solve this ?

ynonp commented 6 years ago

Several options:

  1. Create the ref based on the index, saving an array of items (for example this.refs[idx] = el)

  2. Don’t use ref. Instead save the count as part of the item data in state. Update it in onChange

  3. In the onClick handler use querySelector and closest to find the DOM nodes representing the units count corresponding to the clicked button (something like e.target.closest(tr).querySelector(“input”)

On Mon, 12 Feb 2018 at 16:24 wmashal notifications@github.com wrote:

I still have problem with the text fields where we update units 1- add 3 items in the list 2- try to update the unit in the first row , (not works)

this becuase the ref={unitsNo => { this.unitsNo = unitsNo }} always works with the last text filed in the table what u suggest to solve this ?

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/tocodeil/react-course-examples/pull/32#issuecomment-364936927, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH2UnxRy8dSYi6tgYYIxReeuHGPcsJjks5tUEmjgaJpZM4SAjmp .