Skip to content

Commit

Permalink
docs: format code in examples in guides/fetching-data.mdx (#928)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
zobweyt and kodiakhq[bot] authored Oct 30, 2024
1 parent f4c1efb commit 8190d27
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/routes/guides/fetching-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ When there is a change in the source signal, an internal fetch process is trigge
```jsx
import { createSignal, createResource, Switch, Match, Show } from "solid-js";

const fetchUser = async (id) =>
{
const fetchUser = async (id) => {
const response = await fetch(`https://swapi.dev/api/people/${id}/`);
return response.json();
}
Expand Down Expand Up @@ -63,7 +62,6 @@ function App() {
<div>{JSON.stringify(user())}</div>
</Match>
</Switch>

</div>
);
}
Expand Down Expand Up @@ -91,7 +89,7 @@ import { createSignal, createResource, Switch, Match, Suspense } from "solid-js"
const fetchUser = async (id) => {
const response = await fetch(`https://swapi.dev/api/people/${id}/`);
return response.json();
}
}

function App() {
const [userId, setUserId] = createSignal();
Expand All @@ -106,7 +104,6 @@ function App() {
onInput={(e) => setUserId(e.currentTarget.value)}
/>
<Suspense fallback={<div>Loading...</div>}>

<Switch>
<Match when={user.error}>
<span>Error: {user.error.message}</span>
Expand Down Expand Up @@ -152,15 +149,19 @@ function TodoList() {
<>
<ul>
<For each={tasks()}>
{task => (
{(task) => (
<li>{task.name}</li>
)}
</For>
</ul>
<button onClick={() => {
mutate((todos) => [...todos, "do new task"]) // add todo for user
// make a call to send to database
}}>Add Task</button>
<button
onClick={() => {
mutate((todos) => [...todos, "do new task"]); // add todo for user
// make a call to send to database
}}
>
Add Task
</button>
</>
);
}
Expand Down

0 comments on commit 8190d27

Please sign in to comment.