Devographics / Monorepo

Monorepo containing the State of JS apps
surveyform-sigma.vercel.app
Other
124 stars 50 forks source link

start TextList with 2 fields instead of 1 #284

Closed eric-burel closed 11 months ago

eric-burel commented 11 months ago

All in the title: image

The tricky part is not really to start with 2 fields, but to handle those fields afterwards.

eric-burel commented 11 months ago

This PR https://github.com/Devographics/Monorepo/pull/279 alters the value rather than using "virtual" last items. The problem is that it may mess up the value we store and complicates empty inputs deletion.

Instead we should turn lastItem into lastItems or virtualItems. This means:

It complicates the current code too much, a reducer should be involved to have a clearer state here, with operations to make a virtual input real, manage the number or virtual inputs etc.

eric-burel commented 11 months ago

Done, the hook that handle virtual/real items is reusable and could serve controlled or uncontrolled components (it could be used in the CheckboxGroup namely). It would benefit from being rewritten with "useReducer" (should have started there...) but works well.