useFormAction
react-router

useFormAction

useFormAction(action, props): string

Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.

This is used internally by Form resolve the action to the closest route, but can be used generically as well.

import { useFormAction } from "react-router";

function SomeComponent() {
  // closest route URL
  let action = useFormAction();

  // closest route URL + "destroy"
  let destroyAction = useFormAction("destroy");
}

Parameters

  • action: string
  • props: { relative: RelativeRoutingType, }
Docs and examples CC 4.0