smalljs$molSearch⌘ KDocsPlaygroundCompareEcosystemAboutEN
CookbookGetting StartedIntroductionMental modelGetting StartedFrom TypeScript to view.treeProject StructureToolingEssentialsInstallationViewsState & ReactivityRoutingRenderingTestingDeploymentTroubleshootingDataData FetchingData SchemasGiper BazaMoreShowcaseFrom React, Vue & SvelteCookbookAdvancedPluginsModule metadataOfflineGhost viewsAboutFAQTeamReleasesAPI$mol_button_major$mol_button_minor$mol_string$mol_number$mol_text$mol_paragraph$mol_list$mol_row$mol_link$mol_check$mol_switch$mol_select$mol_scroll$mol_page$mol_pick

Cookbook

Short, copy-ready recipes for tasks that come up in almost every app. Each one is real $mol code — adapt the names and drop it in.

A two-way bound input

Keep an input and a derived value in sync with no handler wiring: <=> binds both directions, and any computed property that reads the value updates on its own.1$my_greeter $mol_view2 sub /3 <= Name $mol_string4 value? <=> name?5 <= Hello $mol_view6 sub / <= greeting \1namespace $.$$ {2 export class $my_greeter extends $.$my_greeter {3 @ $mol_mem name( next?: string ) { return next ?? '' }4 5 @ $mol_mem greeting() {6 return this.name() ? `Hello, ${ this.name() }!` : 'Type your name'7 }8 }9}

A list you can add to and remove from

Hold the collection in a reactive property and rewrite it immutably from actions. A keyed Row* renders one row per item, and — thanks to virtualized rendering — only the visible rows are built.1$my_todo $mol_view2 draft? \3 items /4 sub /5 <= Input $mol_string6 value? <=> draft?7 hint \New item8 <= Add $mol_button_major9 click? <=> add?10 sub / <= add_label \Add11 <= List $mol_list12 rows <= item_rows /13 Row* $mol_row14 sub /15 <= Label* $mol_view16 sub / <= item_title* \17 <= Delete* $mol_button_minor18 click? <=> delete*?19 sub / <= delete_label \✕1namespace $.$$ {2 export class $my_todo extends $.$my_todo {3 @ $mol_mem draft( next?: string ) { return next ?? '' }4 @ $mol_mem items( next?: readonly string[] ) { return next ?? [] }5 6 @ $mol_action add() {7 const title = this.draft().trim()8 if( !title ) return9 this.items([ ... this.items(), title ])10 this.draft( '' )11 }12 13 @ $mol_action delete( id: number ) {14 this.items( this.items().filter( ( _, i ) => i !== id ) )15 }16 17 item_title( id: number ) { return this.items()[ id ] }18 19 item_rows() {20 return this.items().map( ( _, id ) => this.Row( id ) )21 }22 }23}
Edit this page on GitHubWas this helpful?YesNoPreviousFrom React, Vue & SvelteNextPlugins
On this pageA two-way bound inputA list you can add to and remove fromFetch data with loading and error statesPersist local stateRead and write a route parameterAdd an automatic light/dark themeNext
Type to search the documentation.