Skip to content

Commit

Permalink
docs: Add src dir limitation to slices and useStaticQuery (#37326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhopp authored Dec 23, 2022
1 parent 5498013 commit 250c8b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/docs/how-to/querying-data/use-static-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,19 @@ Static queries thus have these limitations:

- `useStaticQuery` does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
- Because of how queries currently work in Gatsby, Gatsby supports only a single instance of `useStaticQuery` in a file

## Other limitations

### Must be in `src` directory

`useStaticQuery` must be used in files that are nested below your site's top-level `src` directory. For example:

`useStaticQuery` works in these files:

- `<SITE_ROOT>/src/my-page.js`
- `<SITE_ROOT>/src/components/my-component.js`

`useStaticQuery` **does not** work in these files:

- `<SITE_ROOT>/other-components/other-component.js`
- `<SITE_ROOT>/other-library/other-component.js`
14 changes: 14 additions & 0 deletions docs/docs/reference/built-in-components/gatsby-slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ export const query = graphql`

## Restrictions on using `<Slice>` placeholder

### Must be in `src` directory

Slice placeholders must be used in files that are nested below your site's top-level `src` directory. For example:

Slice placeholders work in these files:

- `<SITE_ROOT>/src/my-page.js`
- `<SITE_ROOT>/src/components/my-component.js`

Slice placeholders **do not** work in these files:

- `<SITE_ROOT>/other-components/other-component.js`
- `<SITE_ROOT>/other-library/other-component.js`

### Nested Slices

Gatsby does not support nested Slice placeholders. This means if you have a high level `<Layout>` component as a slice component, other Slice placeholders cannot exist within that `<Layout>` component anywhere in the tree.
Expand Down

0 comments on commit 250c8b7

Please sign in to comment.