mitosis.config.js
file.
export function MyComponent() {
const state = useStore({
name: 'Steve',
});
return (
<div>
<input value={state.name} onChange={(event) => (state.name = event.target.value)} />
</div>
);
}
{
"@type": "@builder.io/mitosis/component",
"state": {
"name": "Steve"
},
"nodes": [
{
"@type": "@builder.io/mitosis/node",
"name": "div",
"children": [
{
"@type": "@builder.io/mitosis/node",
"bindings": {
"value": "state.name",
"onChange": "state.name = event.target.value"
}
}
]
}
]
}
import Context from './simple.context.lite';
import { useContext, setContext } from '@builder.io/mitosis';
export default function ComponentWithContext(props: { content: string }) {
// you can access the context using `useContext`
const foo = useContext(Context);
// you can use `setContext` to provide a new value for the context
setContext(Context, {
foo: 'baz',
content() {
return props.content;
},
});
return (
// you can also use `Context.provider` to provide a new value for the context
<Context.Provider value={{ bar: 'baz' }}>{foo.value}</Context.Provider>
);
}
useRef
useStyle
useMetadata
useDefaultProps
onInit
onMount
onUnMount
onUpdate
npm create mitosis
template