Guides

Data fetching

Edit this page

This guide provides practical examples of common data-fetching tasks in SolidStart.

Here's an example showing how to create a query and access its data with the createAsync primitive:


Showing loading UI

To show a loading UI during data fetching:

  1. Import Suspense from solid-js.
  2. Wrap your data rendering in <Suspense>, and use the fallback prop to show a component during data fetching.

Handling errors

To show a fallback UI if the data fetching fails:

  1. Import ErrorBoundary from solid-js.
  2. Wrap the data rendering in <ErrorBoundary>, and use the fallback prop to show a component if an error occurs.

Preloading data

To preload data before a route renders:

  1. Export a route object with a preload function.
  2. Run your query inside the preload function.
  3. Use the query as usual in your component.

Passing parameters to queries

When creating a query that accepts parameters, define your query function to take any number of parameters:


Using a database or an ORM

To safely interact with your database or ORM in a query, use a server function:


Fetching data on the client

To fetch data only on the client, use the createResource primitive:

See the createResource API reference for more information.

Report an issue with this page