Arguments
- value
The payload to expose via
useLoaderData()/useActionData(). Either an R object (list, vector, data.frame – serialized to JSON), or aJSexpression for a JavaScript value.- init
Optional. Either a list with
status(integer),statusText(character) and/orheaders(named list), or aJSexpression evaluating to such an object.
Details
Returns a JS loader function that resolves to a React Router
data() response – a thin wrapper that lets you attach an HTTP
status, statusText, and/or headers alongside the
loader/action payload while still exposing value via
useLoaderData / useActionData.
Use the R helper for static loaders that always return the same value plus
status. For values computed inside a custom loader/action, call
window.jsmodule['@/reactRouter'].helpers.data(value, init) directly
in your JS() string, e.g.
loader = JS("async () => {
const { data } = window.jsmodule['@/reactRouter'].helpers;
const rows = await fetchRows();
return data({ rows }, { status: 200 });
}")Examples
if (FALSE) { # \dontrun{
Route(
path = "/profile",
loader = dataResponse(
list(name = "Ada", role = "Engineer"),
init = list(status = 200)
),
element = useLoaderData(tags$pre())
)
} # }
