DEV Community

Alex Spinov
Alex Spinov

Posted on

Qwik Has a Free API — Here's How to Build Instant-Loading Web Apps

Qwik is a web framework that delivers instant-loading apps by resuming execution on the client instead of hydrating. It ships near-zero JavaScript on initial page load.

Getting Started

npm create qwik@latest
cd my-app
npm run dev
Enter fullscreen mode Exit fullscreen mode

Components with useSignal

import { component$, useSignal } from "@builder.io/qwik";

export const Counter = component$(() => {
  const count = useSignal(0);

  return (
    <div>
      <p>Count: {count.value}</p>
      <button onClick$={() => count.value++}>+1</button>
    </div>
  );
});
Enter fullscreen mode Exit fullscreen mode

useStore — Complex State

import { component$, useStore } from "@builder.io/qwik";

export const TodoApp = component$(() => {
  const state = useStore({
    todos: [
      { id: 1, text: "Learn Qwik", done: false },
      { id: 2, text: "Build app", done: false }
    ],
    newTodo: ""
  });

  return (
    <div>
      <input bind:value={state.newTodo} />
      <button onClick$={() => {
        state.todos.push({ id: Date.now(), text: state.newTodo, done: false });
        state.newTodo = "";
      }}>Add</button>

      {state.todos.map(todo => (
        <label key={todo.id}>
          <input type="checkbox" checked={todo.done}
            onChange$={() => { todo.done = !todo.done; }} />
          {todo.text}
        </label>
      ))}
    </div>
  );
});
Enter fullscreen mode Exit fullscreen mode

routeLoader$ — Server Data Loading

import { routeLoader$ } from "@builder.io/qwik-city";

export const useProducts = routeLoader$(async () => {
  const res = await fetch("https://api.example.com/products");
  return res.json();
});

export default component$(() => {
  const products = useProducts();
  return (
    <ul>
      {products.value.map(p => <li key={p.id}>{p.name} — ${p.price}</li>)}
    </ul>
  );
});
Enter fullscreen mode Exit fullscreen mode

routeAction$ — Form Handling

import { routeAction$, Form } from "@builder.io/qwik-city";

export const useCreatePost = routeAction$(async (data) => {
  await db.post.create({ data: { title: data.title, content: data.content } });
  return { success: true };
});

export default component$(() => {
  const action = useCreatePost();
  return (
    <Form action={action}>
      <input name="title" required />
      <textarea name="content" required />
      <button type="submit">Create</button>
    </Form>
  );
});
Enter fullscreen mode Exit fullscreen mode

Why Qwik?

  • Resumability — no hydration, instant interactivity
  • Near-zero JS on initial load
  • Lazy loading of event handlers — code loads on interaction
  • Built-in SSR with Qwik City

Need to extract or automate web content at scale? Check out my web scraping tools on Apify — no coding required. Or email me at spinov001@gmail.com for custom solutions.

Top comments (0)