I created a sandbox of my react-hook-form demo.
You'll notice all my fields are virtual, there is no input component for them:
const form = useForm({
defaultValues: {
groups: {}
}
});
So you see my default values start at: { groups: {} }.
I am able to successfully add a group like this:
form.register(`groups.${groupId}`);
form.setValue(`groups.${groupId}`, { name: "foo" });
Doing this is good, I expect this behavior, it makes my values now: { groups: { [groupId]: { name: 'foo' } }
However when I try to delete with:
form.unregister(`groups.${groupId}`)
It deletes the entire groups object. My values unexpectedly is now {}. I was expecting it to be { groups: {} }.
Any ideas?