Develop you app's sidebar elements
To create the element, create a file inside pages
and name it google-serp-preview.tsx
with the following content:
import { Wrapper } from '@hygraph/app-sdk-react';export default function GoogleSerpPreview() {return <Wrapper>// here goes your custom sidebar code</Wrapper>;}
In this example, you are naming the file google-serp-preview.tsx
because at the time of registering the app you used http://localhost:3000/google-serp-preview
as your URL
.
Please note that Wrapper should be the parent of your component whenever you use the useFormSidebarExtension
hook.
Adding React SDK
Now, let's import some SDK components and hooks from Hygraph SDK.
Start with importing the Wrapper
component and useFormSidebarExtension
hook from the library inside your React application.
You should add the following code at the top of the google-serp-preview.tsx
file.
// Add this at the top of your google-serp-preview.tsx fileimport { Wrapper, useFormSidebarExtension } from '@hygraph/app-sdk-react';
Then, add useFormSidebarExtension
hook into SerpPreview
and adjust the code accordingly, like the following example:
import { Wrapper, useFormSidebarExtension } from '@hygraph/app-sdk-react';const SerpPreview = () => {const { extension } = useFormSidebarExtension();return (<><h3>{extension.name}</h3><div>{extension.description}</div></>);};
Finally, let's wrap our custom input field with the Wrapper
component. Remember to pass in declaration:
const GoogleSerpPreview = () => {return (<Wrapper><SerpPreview /></Wrapper>);};export default GoogleSerpPreview;
Your complete custom sidebar code should look like this:
// this is the complete codeimport { Wrapper, useFormSidebarExtension } from '@hygraph/app-sdk-react';const SerpPreview = () => {const { extension } = useFormSidebarExtension();return (<><h3>{extension.name}</h3><div>{extension.description}</div></>);};const GoogleSerpPreview = () => {return (<Wrapper><SerpPreview /></Wrapper>);};export default GoogleSerpPreview;
Finally, you should import your custom React component to App.js
.
// App.jsimport GoogleSerpPreview from './extensions/GoogleSerpPreview';function App() {return (<div className="App"><GoogleSerpPreview /></div>);}export default App;
Congratulations! Now that you've registered and developed your app, you are ready to install it and try it out, if you didn't install it already while testing it!
You may also want to access more in depth information about the app registration process, along with all the options available as well as all possible actions you can take in the registration form. Click here to know more.
If you have any questions, you're welcome to join our community!