% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{dataResponse}
\alias{dataResponse}
\title{dataResponse (loader/action helper)}
\usage{
dataResponse(value, init = NULL)
}
\arguments{
\item{value}{The payload to expose via \code{useLoaderData()} /
\code{useActionData()}. Either an R object (list, vector, data.frame --
serialized to JSON), or a \code{\link{JS}} expression for a JavaScript
value.}

\item{init}{Optional. Either a list with \code{status} (integer),
\code{statusText} (character) and/or \code{headers} (named list), or a
\code{\link{JS}} expression evaluating to such an object.}
}
\value{
A \code{\link{JS}} expression suitable for the \code{loader} or
  \code{action} argument of \code{\link{Route}}.
}
\description{
\url{https://api.reactrouter.com/v7/functions/react-router.data.html}
}
\details{
Returns a \code{\link{JS}} loader function that resolves to a React Router
\code{data()} response -- a thin wrapper that lets you attach an HTTP
\code{status}, \code{statusText}, and/or \code{headers} alongside the
loader/action payload while still exposing \code{value} via
\code{\link{useLoaderData}} / \code{\link{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
\code{window.jsmodule['@/reactRouter'].helpers.data(value, init)} directly
in your \code{JS()} string, e.g.
\preformatted{
  loader = JS("async () => {
    const { data } = window.jsmodule['@/reactRouter'].helpers;
    const rows = await fetchRows();
    return data(\{ rows \}, \{ status: 200 \});
  }")
}
}
\examples{
\dontrun{
Route(
  path = "/profile",
  loader = dataResponse(
    list(name = "Ada", role = "Engineer"),
    init = list(status = 200)
  ),
  element = useLoaderData(tags$pre())
)
}

}
