[📖] Handling useResource$() without a <Resource />
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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