Anyone used dnd tree with react hook form #1099
Unanswered
PetterRuud
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I'm not sure if I'm addressing your question but conceptually if you have a tree structure as your state, you want to create a function that searches for a node by id (same id as you used in useSortable) and return the name in your register function for react-hook-form. This would require recursive searching of a tree. This is where understanding leetcode tree traversal would help. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A list view with a useFieldArray works fine, as seen here with react-beautiful-dnd.
https://codesandbox.io/s/react-hook-form-usefieldarray-forked-1tzyn?file=/src/index.js
Question is, has anyone tried using React Hook form with DndKit, tree structure, using the example from
https://master--5fc05e08a4a65d0021ae0bf2.chromatic.com/?path=/story/examples-tree-sortable--all-features
The problem as I see it is that you need to get the indexes right for the inputs
For example, lets say you want to change the name for each item in the list.
The {...register(
data.${index}.name
} has to be dynamic based on the tree.So for children it has to know the index path; {...register(
data.${index.children.index}.name
}Example of wanted result
https://share.getcloudapp.com/6quN2ePg
So hoping someone has done it and could share some pointers.
Beta Was this translation helpful? Give feedback.
All reactions