Next.js
Build your first hello world app with Next.js
This guide will walk you through building your first Highlight app with Next.js.
Setup Next.js
The first order of business is to setup Next.js. You should already have Node.js and npm installed on your machine.
Create a new Next app with:
Next will ask you a few questions about your app. You can leave the defaults as they are or customize to your liking.
Test your app
With your app created, change directories into your new app and run:
By default, your Next app will run on http://localhost:3000
.
You can view your running localhost app by:
- Opening the Highlight app (right click Highlight icon in menu/task bar, click “Open Highlight App”)
- Click “Settings” towards the bottom navigation bar.
- Click “Advanced” at the top bar.
- Select the toggle switch next to “Developer Mode”.
- A new Local Development app will appear in your pinned apps. Click it.
Write a suggestions prompt
One of Highlight’s powerful features is showing the user suggestions that explain what your app can help with them with using the context of their screen.
When you use the Highlight hotkey and tab to your app, you will notice no suggestions loading:
This is because we are missing a suggestions prompt.
Create a new file inside your Next app: my-app/public/suggestions.hbs
Paste the following into the file:
After saving, verify you can access your prompt file from a web browser by navigating to http://localhost:3000/suggestions.hbs
.
Update your Next.js configuration to allow Highlight to access the suggestions prompt:
Now, when you activate your Highlight hotkey, you should start seeing suggestions that were generated using your new prompt.
Add Highlight APIs
Now for the fun part. Let’s use Highlight’s Runtime API to discover when the user selects a suggestion.
First, add the Highlight runtime library to your Next project:
Let’s make the main index route of the Next app a client component so that it can access the Highlight runtime API. Then, let’s add an event listener and listen for the onContext event:
Test your app
You’re ready to see your app in action.
First, try opening your app from the sidebar of the main Highlight app.
Notice how no item is shown as selected:
Now, let’s select a suggestion and see what happens.
- Open the Highlight overlay (use the Highlight hotkey).
- With the selected app as Local Development (the top bar of the overlay), select a suggestion item using the arrow keys and press enter on your keyboard.
Your selection will now appear:
Keep building
Congrats! You’ve built your first Highlight app.
You’ve just been given a brief overview of what you can do with Highlight. Continue on to the Runtime API to view the full set of API methods available to you.
Also, join our Discord to chat with the team, other developers, and to get help building your app.