Keywork includes React contexts that are useful for server-side rendering.
These contexts are used to provide hook data to your application, such as the
current request, the current location, and the current environment.
Much of the data provided by these contexts is already available to your app within
your router's callback function, but you can also use these contexts to
access the data within your components in a more React-like way.
::: tip
Generally, you won't need to add these contexts to your application, as
Keywork will automatically add them for you.
:::
The EnvironmentContext provides the current request's env object to your application.
This is useful when interacting with bindings attached to your Cloudflare Worker,
or when you need to access environment variables from Node.js.
The URLMatchContext provides the current request's match object to your application.
This is useful when you need to access a porition of request's URL, such as a slug,
or a query parameter.
Keywork includes React contexts that are useful for server-side rendering. These contexts are used to provide hook data to your application, such as the current request, the current location, and the current environment.
Much of the data provided by these contexts is already available to your app within your router's callback function, but you can also use these contexts to access the data within your components in a more React-like way.
::: tip Generally, you won't need to add these contexts to your application, as Keywork will automatically add them for you. :::
EnvironmentContext
The
EnvironmentContext
provides the current request'senv
object to your application. This is useful when interacting with bindings attached to your Cloudflare Worker, or when you need to access environment variables from Node.js.URLMatchContext
The
URLMatchContext
provides the current request'smatch
object to your application. This is useful when you need to access a porition of request's URL, such as a slug, or a query parameter.useParams
A a convenience hook that returns the route parameters from the current request: