Hooks before or after saving

Hi there, I am wondering how I could add a simple updatedAt field, is there some way to add “afterSave” hooks or something similar?

I’m stupid, you can at least get the “updatedAt” from gatsby itself…

Hey Marc!

So we don’t have an official API for this right now, but rest assured it’s on my mind. A couple of us have been mulling it over and discussing various approaches. It might be close.

That said you can still do this, but it’s a bit hacky. You can reach inside the Form object and create a decorator on the finalForm instance. Here is an example from our website:

  const [values, tinaForm] = useForm( ... )

  useEffect(() => {
    const submitListener = createDecorator({
      afterSubmitSucceeded() {
        cms.alerts.success("Form Saved")
      },
      async afterSubmitFailed(finalForm) {
        setError(finalForm.getState().submitError)
      },
    })

    const undecorateSaveListener = submitListener(tinaForm.finalForm)

    return undecorateSaveListener
  }, [tinaForm])