useFlow Hook
The useFlow
hook sits one layer deeper in the React SDK than the Flow Component and serves as the connection between our vanilla JS data layer and React Components.
In most cases, you’ll want to use <Flow>
over useFlow
, but if you need a deeper level of control over the lifecycle and behavior of a Flow, or if you need access to a Flow outside of a Component, this hook is for you.
In this example, we’ll build a Progress Badge using the useFlow hook for the data layer.
Additionally, we’ll leverage a series of prebuilt Frigade component primitives such as <Box>
to build the UI.
The final result looks like this:
A custom built progress badge
First, create a new Flow in the Frigade Dashboard by navigating to the Flows tab and clicking Create Flow. Select Custom Flow as the Flow type.
You can use any code you wish for the YAML configuration, however, we recommend starting with the following example:
We’re now ready to wire in the frontend code. Start by simply importing the useFlow
hook. We’ll then use the hook to get the flow data and calculate the number of steps completed and the total number of steps:
To see the full list of methods and fields in the flow
object, see the Flow API Reference.
Now, all we have left to do is to build the UI. We’ll use the Box
and Text
components from the Frigade React SDK to build the UI. We’ll also use the IconRender
component to render the ChevronRight icon from the lucide-react
package:
That’s it! You’ve built a custom component using the Frigade React SDK.