Skip to content

Commit 200e59e

Browse files
sukvvonKevinVandy
andauthored
feat(landing/codeExamples): add 'lit-query' code example to query quick start (#906)
* feat(landing/codeExamples): add 'lit-query' code example to query quick start * style(landing/codeExamples): add blank lines around early returns in 'lit' query example --------- Co-authored-by: Kevin Van Cott <kevinvandy656@gmail.com>
1 parent 3f880e5 commit 200e59e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/components/landing/codeExamples.server.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,29 @@ export class TodosComponent {
134134
}
135135
`,
136136
},
137+
lit: {
138+
lang: 'ts',
139+
code: `import { LitElement, html } from 'lit'
140+
import { customElement } from 'lit/decorators.js'
141+
import { createQueryController } from '@tanstack/lit-query'
142+
143+
@customElement('todos-list')
144+
export class TodosList extends LitElement {
145+
private todos = createQueryController(this, {
146+
queryKey: ['todos'],
147+
queryFn: () => fetch('/api/todos').then(r => r.json()),
148+
})
149+
150+
render() {
151+
const { data, isPending, error } = this.todos.current
152+
153+
if (isPending) return html\`<span>Loading...</span>\`
154+
if (error) return html\`<span>Oops!</span>\`
155+
156+
return html\`<ul>\${data.map(t => html\`<li>\${t.title}</li>\`)}</ul>\`
157+
}
158+
}`,
159+
},
137160
},
138161
}
139162

0 commit comments

Comments
 (0)