Atom-Learning/components

Feature request: Form Component - localStorage persist functionality

LeahB8 opened this issue · 8 comments

Add persist to sessionStorage functionality to the form component

Form.tsx

Description

  • Integrate persist functionality for the form using sessionStorage
  • As a USER I want to be able to keep my form data between refreshes
  • As a DEV I want an integrated and easy to use option to retain form data between refreshes so I don't have to write a custom approach each time

Hi @LeahB8, could we get more details on this?

What are the use cases where we need to add this in the form component? Ie, what problem are we trying to address

Hi @LeahB8, could we get more details on this?

What are the use cases where we need to add this in the form component? Ie, what problem are we trying to address

Tom suggested adding this as I was in the process of writing a custom approach to doing this in the new sign up journey forms. I know multiple places on the app that could use this functionality where I or someone else have written a custom approach (localStorage or redux) which can get quite messy.

@hollg @LeahB8 Should we close this issue or keep it open until we fix the issues with it?

@hollg @LeahB8 Should we close this issue or keep it open until we fix the issues with it?

We could keep it open until the issues are fixed

hollg commented

I think it's worth keeping this open.

The issues that I'm aware of with the current implementation are:

  • react-hook-form itself doesn't provide a way to read default values via useFormContext()
  • react-hook-form-persist doesn't interact at all with default values for the form

Consequently it's difficult to get persisted values into our complex field components (i.e. the ones that involve a Controller) because in those ones we have to manage default values ourselves.

To solve this issue I think we should:

  • add functionality to our Form to make default values accessible to the nested field components (maybe a custom hook?)
  • add our own persistence logic that correctly updates default values for complex field components

@hollg do you think this is still relevant to keep open?

This issue is stale because it has been open for a year with no activity. Remove stale label or comment or this will be closed in 7 days.

This issue was closed because it has been stalled for a year with no activity.