willowtreeapps / react-formable

React Forms
25 stars 5 forks source link

Abandon using refs for inputs #99

Closed kaw2k closed 6 years ago

kaw2k commented 7 years ago

With making normalizeInput I can foresee a world where we forgo ref all together. We can still clone children and pass down onChange (by convention) and enforce that onChange passes up the value of the input. Making the form tree would be trickier perhaps... I think we would get big wins in speed and maintainability. Also, I think the public API would remain largely unchanged. Will delay this until after v1 ships.

kaw2k commented 7 years ago

Going to use this issue as a vague roadmap so I don't forget 😄

  1. When cloning our children to pass down additional props (like fieldErrors, etc) we would use that time to build a tree and store it to our instance (not state since it would be in the render function)
  2. The onChange function would need to tag each input with the id of the leaf of the tree it belongs to. This could cause performance hits on large trees as we would be generating new functions /shrug
  3. When we are building the tree, we would need to do all our prop work on an input basis there (get validators , etc)
  4. Our clone children would need to be more aggressive than it is now with filtering non formable inputs.

Since all of this would be happening on render, we would need to optimize this process quite a bit more than we are doing now. Still, the more I think about it the more feasible it is.