QwikDev / QwikDev/qwik

[📖] Handling useResource$() without a <Resource />

Open
#6,955 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

docs PR welcomed
Dominant language
TypeScript
Stars
22.1k
Forks
1.4k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

Suggestion

adding a explicit example on how to handle the case
https://discord.com/channels/842438759945601056/1293247102637441064/1293570046924161055

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

export const NoResourceNeeded = component$(() => {
  const tracked = useSignal(0);
  const resolvedValue = useSignal<number>();
  const rejectedValue = useSignal<any>();

  const resource = useResource$(({ track }) => {
    const value = track(() => tracked.value);

    return value + 1;
  });

  useTask$(async ({ track }) => {
    const promise = track(() => resource.value);

    try {
      resolvedValue.value = await promise;
    } catch (e) {
      rejectedValue.value = e;
    }
  });

  return (
    <div>
      {resource.loading && <div>Loading...</div>}
      {resolvedValue.value && <div>Resolved: {resolvedValue.value}</div>}
      {rejectedValue.value && <div>Rejected: {rejectedValue.value}</div>}

      <button onClick$={() => tracked.value++}>Click</button>
    </div>
  );
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing documentation for useResource$ and read how resource loading, resolution, and rejection are currently explained. Add an explicit TypeScript example covering useResource$ without a Resource component, using the scenario shown in the issue; the documentation is complete when that case and its loading, resolved, and rejected states are clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.