TanStackT
TanStack6mo ago
7 replies
foolish-indigo

dynamic defaultValues

I am implementing a CMS. We have two tabs : "Draft" and "Published". They are showing different fields of the TS Form: draft.content , draft.title and published.content, published.title.

On the "Draft" tab there are "Publish" and "Save draft" buttons.
- Publish button is submitting the data as "published" entry, and then deletes the "draft" entry, and resets the draft.xxx fields, and resets the default values for the published.xxx fileds.
- Save draft button is saving the values as "draft" entry (idk if the form should be reset in this case?...)

On the "Published" tab there are "Save as Draft" and "Update published" buttons.

- Save as Draft button would create a "draft" entry in db and reset the published.xxx fields back to initial values (that were fetched from API)
- Update published button would update a "published" entry in db (same as with "Save draft" button, idk, if the form should be reset in this case)


My current solution is to use
useEffect
every time the fetched data changes and manually reset the form content to the updated data..

Does anybody did something similar? I would appreciate any ideas
Was this page helpful?