We’ve made a CodeSandbox project for the examples below so
you can play around with the code.
Example 1 - Magic link login form
For our example app, we’ll build a simple magic link login form. This is what we want the end-result to look like:
- We add a fake fetch function that simulates a network request and a
handleSubmit
function that handles the form submission. - We also want to update our Button to show that we’re currently submitting the form, so we’ll maintain a
submitting
state variable and pass it to the Button in thedisabled
andloading
props.
Example 2 - Interactive track cards
We now want to build a feature where we show the user their most-listened-to tracks of the past week and allow them to favorite tracks so they can easily find them later. When adding business logic to Subframe-designed components, we recommend not editing the generated code inside thesrc/ui/
directory directly, but instead wrapping the component.
We built a TrackCard
component and FavoriteTracks
page in Subframe and brought them to our codebase:

- We’ll wrap the original
TrackCard
component with a new component that will manage the simple business logic. - We’ll use this wrapper component in our
FavoriteTracks
page which manages the data, thefavorite
state, and provides the onClick handlers.