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

default discord avatar
Cerizelast year
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?

  • discord user avatar
    jmikrut
    last year

    yeah you will need to send

    null

    to clear a field

  • default discord avatar
    Cerizelast year

    thanks @jmikrut for confirming!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.