You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Small update to guide on fetching external API (#5900)
* small fix to server function
* ci: apply automated fixes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
## Step 3: Creating the Route with API Fetch Function
117
117
118
-
Now let's create our route that fetches data from the TMDB API. Create a new file at `src/routes/fetch-movies.tsx`:
118
+
To call the TMDB API, we're going to create a server function that fetches data on the server. This approach keeps our API credentials secure by never exposing them to the client.
119
+
Let's create our route that fetches data from the TMDB API. Create a new file at `src/routes/fetch-movies.tsx`:
-`createServerFn()` creates a server-only function that runs exclusively on the server, ensuring our `TMDB_AUTH_TOKEN` environment variable never gets exposed to the client. The server function makes an authenticated request to the TMDB API and returns the parsed JSON response.
164
+
- The route loader runs on the server when a user visits /fetch-movies, calling our server function before the page renders
165
+
- Error handling ensures the component always receives valid data structure - either the movies or an empty array with an error message
166
+
- This pattern provides server-side rendering, automatic type safety, and secure API credential handling out of the box.
167
+
163
168
## Step 4: Building the Movie Components
164
169
165
170
Now let's create the components that will display our movie data. Add these components to the same `fetch-movies.tsx` file:
Copy file name to clipboardExpand all lines: docs/start/framework/react/tutorial/reading-writing-file.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ id: reading-and-writing-file
3
3
title: Building a Full Stack DevJokes App with TanStack Start
4
4
---
5
5
6
-
This tutorial will guide you through building a complete full-stack application using TanStack Start. You'll create a DevJokesapp where users can view and add developer-themed jokes, demonstrating key concepts of TanStack Start including server functions, file-based data storage, and React components.
6
+
This tutorial will guide you through building a complete full-stack application using TanStack Start. You'll create a DevJokes app where users can view and add developer-themed jokes, demonstrating key concepts of TanStack Start including server functions, file-based data storage, and React components.
0 commit comments