This video is available to students only

Prepare the Example App as a Public Example Page

So far you've been using the example application soley for your own internal testing.

But with a bit of effort, you can turn it into an interactive example page!

Add Bootstrap to the Example App#

You'll use Bootstrap to style the example app. The create-react-app documentation recommends the following steps for adding Bootstrap to a create-react-app. First, install bootstrap:

Then, in src/index.ts, you can import the bootstrap CSS file:

Add a Container to the Example App#

Get started by creating markup for the example page in App.tsx. The idea is using Bootstrap's container class to wrap around the entire app, making the page responsive and nicer to look at all around:

Add Header Markup#

You can start adding some information about usePleaseStay itself within the container div:

Add State Variables for all usePleaseStay parameters#

For each parameter than can be passed to usePleaseStay, you should make a trackable state value for it, and then build a proper UI element for each. Start with the state variables, picking sensible defaults later on:

and below these state variables, you can call usePleaseStay:

Build an Interactive Form for Each Hook Field#

For the titles, you can use a textarea and prompt to the user that they can comma separate each title. Due to the custom type ArrayOfOneOrMore, you need to use a bit of custom syntax by using the first title and then spreading the rest of the titles:

For the interval, also add an input of type number:

For the animationType, use a radio button group, since only one type of animationType can be selected at a time:

This lesson preview is part of the Master Custom React Hooks with TypeScript course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to Master Custom React Hooks with TypeScript, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Master Custom React Hooks with TypeScript