The useSection hook in deco.cx is a powerful tool designed to automatically generate links for updating and rendering sections. With this hook you can use HTMX or Fresh's Partials to render specific section states. Below is a detailed explanation of its usage, parameters, and examples.
Importing the useSection Hook
To use the useSection hook, you need to import it from the deco/hooks/useSection.ts file:
import { useSection } from "deco/hooks/useSection.ts";
Parameters
The useSection hook accepts an options object with the following properties:
props: An object containing the section props to override. This allows you to specify new values for props that will be used to render the section. Keep in mind that props are merged with those from the current section instance.
href: A string representing the new URL to evaluate this section. This URL will be used for the Request parameter on all loaders/actions this section may depend on.
Return Value
The useSection hook returns a URL string of the section with the props partially applied
Example Usage
Let's build a component that print an integer and allow us to see the next integer. Here's a print
This component can be built with the following code:
Where useSection returns a link for the next integer.
Warnings
URL Size Limits: Be mindful of the URL size limits when passing props to useSection. Try to keep payloads small and use lightweight data types like booleans and IDs.
Security: Ensure that any sensitive data passed as props is properly secured and does not expose vulnerabilities through the URL.
useSection
API ReferenceThe
useSection
hook in deco.cx is a powerful tool designed to automatically generate links for updating and rendering sections. With this hook you can use HTMX or Fresh's Partials to render specific section states. Below is a detailed explanation of its usage, parameters, and examples.Importing the useSection Hook
To use the useSection hook, you need to import it from the deco/hooks/useSection.ts file:
Parameters
The useSection hook accepts an options object with the following properties:
Request
parameter on all loaders/actions this section may depend on.Return Value
The useSection hook returns a URL string of the section with the props partially applied
Example Usage
Let's build a component that print an integer and allow us to see the next integer. Here's a print
This component can be built with the following code:
Where useSection returns a link for the next integer.
Warnings