Next.js
Prerequisites
Before you start, make sure you:
- Generate your Coval API key from using the Authentication Guide.
- Create a Next.js application — Learn More.
1. Full Stack Solution: Use React components to create Full Stack Next.js App
Install Coval SDK
Begin by installing the
@coval/nextjs
for the nextjs specific implementation of the client@coval/react
for the embedding the ui components in your project and connecting to the Coval Client
Set your Coval API keys
Set up Proxy Path
A proxy path in Next.js is a way to redirect or rewrite API requests to different URLs, typically used to avoid CORS issues or to hide sensitive backend URLs.
Create a proxy path file in your nextjs project under /pages/api/[...proxyPath].ts
and add the following code. Feel also free to make other modifications to the proxy code to fit your needs:
Declare the Coval Client
The coval nextjs library needs to be initialized on the client-side using the Next.js ‘use client’ directive. You can do this in the app router or in a separate file.
Add <CovalProvider> and Coval Launch Evaluation Component to your app
You can import the CovalProvider component into your app/layout file and wrap your app with it.
Alternatively, here is another example of how you can embed and launch an evaluation.
You can also use the useCoval
hook to access the Coval client in your components.
Let’s say you want to create yout own function to fetch metrics and pass them to the LaunchEvalButton component.
Great! Now you can write your own data fetching logic and pass it to the Coval components.
Was this page helpful?