Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TUTORIAL: useResource now has a task #1151

Merged
merged 3 commits into from
Nov 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@ export const App = component$(() => {
org: 'BuilderIO',
});

const reposResource = useResource$<string[]>(({ track, cleanup }) => {
// We need a way to re-run fetching data whenever the `github.org` changes.
// Use `track` to trigger re-running of the this data fetching function.
track(github, 'org');

// A good practice is to use `AbortController` to abort the fetching of data if
// new request comes in. We create a new `AbortController` and register a `cleanup`
// function which is called when this function re-runs.
const controller = new AbortController();
cleanup(() => controller.abort());

// Fetch the data and return the promises.
return getRepositories(github.org, controller);
});
// Use useResource$() to set up how the data is fetched from the server.
// See the example for Fetching Data in the text on the left.

console.log('Render');
return (
Expand All @@ -32,20 +20,17 @@ export const App = component$(() => {
/>
</span>
<div>
<Resource
value={reposResource}
onPending={() => <>Loading...</>}
onRejected={(error) => <>Error: {error.message}</>}
onResolved={(repos) => (
{/* Use <Resource> to display the data from the useResource$() function. */}
{/* To help, here's a callback function to display the data on resolved. */}
{/* (repos) => (
<ul>
{repos.map((repo) => (
<li>
<a href={`https://github.com/${github.org}/${repo}`}>{repo}</a>
</li>
))}
</ul>
)}
/>
) */}
</div>
</div>
);
Expand Down