Function: newWidget()
newWidget(
id,content):Widget
Defined in: packages/core/src/passages/widget.ts:146
Factory function for creating Widget passages.
Important: When passing a function, it is always treated as a React
component and rendered via createElement. This ensures hooks work correctly
even in minified production builds where function names are mangled.
Parameters
id
string
Unique identifier for the widget
content
React node or React functional component to display
Returns
New Widget instance
Remarks
Fully supported and not scheduled for removal. New code is encouraged to use
defineWidget, which is identical but keeps every passage factory
under the same define* name.
Example
// With ReactNode (static content)
const customMenu = newWidget('menu', (
<CustomMenuComponent />
));
// With React component (supports hooks)
const MyComponent = () => {
const [count, setCount] = useState(0);
return <Counter count={count} onChange={setCount} />;
};
const counterWidget = newWidget('counter', MyComponent);
// For dynamic content without hooks, pre-evaluate:
const timestampWidget = newWidget('time', (() => <div>{Date.now()}</div>)());