Forge offers two ways to build user interfaces for your apps:
It's important to note that UI Kit relies only on the @forge/react
components and does not directly rely on React DOM. Therefore, functionalities dependent on standard browser DOM elements, like custom HTML, portals, and forwarding refs, may not work as expected.
Let's look at the fundamental elements of building user interfaces with Forge, namely the Product APIs and Components. We'll also explore how to declare and use 'resources
' and 'resolvers
', which are the key concepts in UI development.
API requests to products can be made in the frontend using @forge/bridge
, typically in your
App.js
file. For more information, see
Forge bridge APIs.
User interfaces can be built using components. These are native and reusable building blocks created to streamline the development of user interfaces.
Resource allows you to define your own user interface using static resources, such as HTML, CSS, JavaScript, and images.
UI Kit allows only images. However, in the case of custom UI, there are no restrictions on loading any of the previously mentioned resources.
UI Kit expects your app to have the following dependencies installed at the top-level directory:
1 2npm i react@18 npm i @forge/react@latest
In UI Kit, the following directory and UI entry point file should be added to your app /src
folder:
1 2/src /frontend /index.jsx
In Custom UI, the following directory and UI entry point file should be added to your app /src
folder:
The specified folder structure /static/src/index.js
is not mandatory; instead, ensure that the index.html
file is located at the path specified in your resource's configuration.
1 2/static /src /index.js
In UI Kit, the React dependencies should be imported, and the Forge render method should be called in the
/src/frontend/index.jsx
file of your app.
1 2import React, { useEffect } from 'react'; import ForgeReconciler, { Box, Text } from '@forge/react'; const App = () => ( <Box> <Text>Hello, world!</Text> </Box> ) ForgeReconciler.render( <React.StrictMode> <App /> </React.StrictMode> );
In Custom UI, the React dependencies should be imported, and the ReactDOM
render method should be called in the /static/src/index.js
file of your app.
1 2import React from 'react'; import ReactDOM from 'react-dom'; const App = () => ( <div> Hello, world! </div> ) ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById('root') );
A resource should be declared in the app manifest.
1 2resources: - key: frontend path: src/frontend/index.tsx
Resolver enables you to define backend functions for your UI Kit and custom UI apps.
The following dependency should be installed at the top-level directory of your app:
1 2npm i @forge/resolver@latest
The following directory and UI entry point file should be added to your app /src
folder:
1 2/src /backend /index.js
The resolver dependency should be imported, and your resolvers defined in your app /src/backend/index.js
file.
1 2import Resolver from '@forge/resolver'; const resolver = new Resolver(); resolver.define('my-example', async (req) => { return { data: 'Hello, world', } }); export const handler = resolver.getDefinitions();
A function should be declared in the app manifest.
1 2modules: function: - key: backend handler: index.handler
To integrate your app, it needs to be declared in a
module. Modules necessitate a resource
, resolver
,
and a render
mode to display UI in a product.
1 2modules: macro: - key: example title: Example Macro resource: frontend resolver: function: backend
Rate this page: