Split your UI into .mx files and reuse them like React components. Each
instance gets its own local state — two <Counter /> on one page never share
a count.
import Hero from './components/Hero.mx';
import { Card } from './components/ui.mx';
export default function App() {
return (
<body>
<Hero title="hi" />
<Card t="x" />
</body>
);
}Rules:
import Hero from ...) binds the file's default export.import { Card } from ...) bind exported components by name.morph check flags
unknown components (mx-component-unknown) before you compile.Declare props with a typed parameter:
export function Hero(props: { title: string }) {
return <div>{props.title}</div>;
}You can also destructure. At each call site:
mx-component-required).mx-component-prop).key is reserved for list rendering and is never passed as a prop.Props typed as functions accept a named function or an inline arrow:
export function Button(props: { label: string, onPress: () => void }) {
return <button onClick={props.onPress}>{props.label}</button>;
}
export default function App() {
return (
<body>
<Button label="Save" onPress={() => console.log("saved")} />
</body>
);
}Inline arrows on function-typed props are compiled into typed adapters, so they behave like normal callbacks.
morphState inside a component belongs to that instance. Rendering <Hero />
twice gives two independent states, even though both run the same code:
import { morphState } from 'morph';
export function Hero(props: { title: string }) {
const [count, setCount] = morphState(0);
return <div>{props.title}: {count}</div>;
}Limitation: components rendered inside a .map() list template currently
share one state slot per template (per-instance state in lists is planned).
Refer to the `morphShared` API documentation for details on creating module-scoped shared state.
Refer to the `morphEvent` API documentation for details on creating typed event channels between components.
Use standard CSS imports. CSS.load() is deprecated:
import "./hero.css";morph check warns with mx-css-load-deprecated on CSS.load() calls.
| Code | Meaning |
|---|---|
mx-component-unknown |
Component tag is neither defined nor imported |
mx-component-prop |
Unknown prop passed to a component |
mx-component-required |
Required prop missing at a call site |
mx-state-scope |
morphState is called inside a component body |
mx-shared-scope |
morphShared is exported at module scope |
mx-event-scope |
morphEvent is exported at module scope |
mx-api-removed |
Removed string-key/shared/event APIs are not used |
mx-css-load-deprecated |
CSS.load() — use import "./x.css" |