03. Calling Component Methods
The Problem
A business screen may need to tell a child component to refresh, save, print, or perform another operation.
The React Difficulty
React generally exposes imperative child operations through refs and `useImperativeHandle`. This is useful, but it introduces an explicit ref-based mechanism for an operation that is naturally a method call.
React Approach
const CustomerEditor = forwardRef(function CustomerEditor(_, ref) {
useImperativeHandle(ref, () => ({
refresh() { /* ... */ },
save() { /* ... */ }
}));
return <div>Editor</div>;
});
const editorRef = useRef(null);
editorRef.current?.refresh();
MS Approach
ManySet provides a direct runtime-oriented approach for this recurring business-application task.
const editor = await ms.inject("./Customers/Editor", "content");
await editor.refresh();
await editor.save();
Why this way is useful in business applications :
The comparison is intended to show where ManySet supplies a business-application abstraction around a recurring task, while keeping HTML and JavaScript visible and directly usable.
Key Point :
ManySet reduces the amount of framework-specific composition required for this particular task, without requiring the React/Angular mechanism to be represented as inherently wrong or incapable.