Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

useFormFields Value and Dispatch

default discord avatar
markatomniux2 years ago
6

Just wanted to leave this in the community in case anyone is wanting to leverage the useFormFields functionality like useState;



    const [status, setStatus]: [string, (value: string) => void] = useFormFields(([fields, dispatch]) => [
        fields.status.value as string, (value: string) => dispatch({ type: 'UPDATE', path: 'status', value: value })
    ]);


This will allow you to use status to get the value, and setStatus('') to make changes to your other form values.

  • default discord avatar
    mvdve10 months ago

    Saved the day, thanks!

  • default discord avatar
    sh_90205 months ago

    hey

    @191776538205618177

    , could you guide me if i want to add a row to type:array using dispatch.

  • default discord avatar
    markatomniux5 months ago

    I'd need to take another look at the docs. This was posted a LOOONNG time ago, probably around v1 or pre-v1. So much has changed now in the way client components are handled - this logic may no longer apply

  • default discord avatar
    sh_90205 months ago

    hey

    @191776538205618177

    thanks for your reply, i managed to solve it

  • default discord avatar
    markatomniux5 months ago

    though it looks like you'd just change type to ADD_ROW

  • default discord avatar
    sh_90205 months ago

    i used the addFieldRow method

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.