I did that. Unfortunately, it didn’t help either. In the IDE, the actions useState, useEffect are marked as unused. The error occurs in react.production.js.
Here are the files and the errors in a bit more detail:
package.json
{
"name": "confluence-macro-custom-ui-static",
"version": "0.1.45",
"private": true,
"homepage": ".",
"dependencies": {
"@atlaskit/css-reset": "^6.6.2",
"@forge/bridge": "4.5.1",
"@forge/react": "^11.2.0",
"react": "^16",
"react-dom": "^16"
},
"devDependencies": {
"react-scripts": "^5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
manifest.yml
modules:
macro:
- key: hello-world-2-hello-world
resource: main
resolver:
function: resolver
title: hello-world-2
description: Inserts Hello world!
config: true
function:
- key: resolver
handler: index.handler
resources:
- key: main
path: static/hello-world-2/build
app:
runtime:
name: nodejs22.x
id: ...
static/hello-world-2/index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import ForgeReconciler, { Label, Textfield, Text, useConfig, SectionMessage } from '@forge/react';
const defaultConfig = {
name: 'Unnamed Pet',
age: '0'
};
// Function that defines the configuration UI for the pet's name and age
const Config = () => {
return (
<>
<Label>Pet name</Label>
<Textfield name="name" defaultValue={defaultConfig.name} />
<Label>Pet age</Label>
<Textfield name="age" defaultValue={defaultConfig.age} />
</>
);
};
const App = () => {
const actualConfig = useConfig();
const config = actualConfig || defaultConfig;
// Displaying the pet's name and age using the configuration values. SectionMessage component is optional.
return (
<>
<Text>{config.name} is {config.age} years old.</Text>
<SectionMessage title="You need to configure this macro" appearance="warning">
<Text>
While editing the page, select the macro, and click on the pencil icon
to display configuration options.
</Text>
</SectionMessage>
</>
);
};
ReactDOM.render(
<App />,
document.getElementById('root')
);
ForgeReconciler.addConfig(<Config />);
Error trace in browser console
react-dom.production.min.js:209 TypeError: Cannot read properties of null (reading 'useState')
at t.useState (react.production.min.js:26:234)
at t.useConfig (useConfig.js:17:45)
at i (index.jsx:23:24)
at Zl (react-dom.production.min.js:153:146)
at Ei (react-dom.production.min.js:261:496)
at Tu (react-dom.production.min.js:246:265)
at xu (react-dom.production.min.js:246:194)
at yu (react-dom.production.min.js:239:172)
at fu (react-dom.production.min.js:230:137)
at Zu (react-dom.production.min.js:281:43)
react-dom.production.min.js:256 Uncaught TypeError: Cannot read properties of null (reading 'useState')
at t.useState (react.production.min.js:26:234)
at t.useConfig (useConfig.js:17:45)
at i (index.jsx:23:24)
at Zl (react-dom.production.min.js:153:146)
at Ei (react-dom.production.min.js:261:496)
at Tu (react-dom.production.min.js:246:265)
at xu (react-dom.production.min.js:246:194)
at yu (react-dom.production.min.js:239:172)
at fu (react-dom.production.min.js:230:137)
at Zu (react-dom.production.min.js:281:43)