Function: newWidget()
newWidget(
id,content):Widget
Defined in: packages/core/src/passages/widget.ts:141
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
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>)());