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
handleSubmitfunction 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
submittingstate variable and pass it to the Button in thedisabledandloadingprops.
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
TrackCardcomponent with a new component that will manage the simple business logic. - We’ll use this wrapper component in our
FavoriteTrackspage which manages the data, thefavoritestate, and provides the onClick handlers.

