Like what we’re doing? Star us on GitHub!

[Possible bug] How to clean a field using the dispatch from useFormFields?

Cerize
3 weeks ago
4

Hi there! I am using useFormFields to get the dispatch method for an UPDATE action. Sometimes I need to clean a field, so I dispatchName(undefined). That clears the form correctly, but when I click 'Save Draft' the old value reappears and is saved in Mongo. Any insights on what's going on?



const dispatchName = useFormFields(


([_, dispatch]) =>


(value: string) =>


dispatch({


type: 'UPDATE',


path: NamePath,


value: value


})


)



dispatchName(undefined)



P.S: it seems to work better with dispatching 'null'



@jmikrut Do you know if have anyone seen this before?

  • jmikrut
    Payload Team
    3 weeks ago

    yeah you will need to send

    null

    to clear a field

  • Cerize
    3 weeks ago

    thanks @jmikrut for confirming!

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More