Skip to content

Commit 250c8b7

Browse files
authored
docs: Add src dir limitation to slices and useStaticQuery (#37326)
1 parent 5498013 commit 250c8b7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docs/docs/how-to/querying-data/use-static-query.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ Static queries thus have these limitations:
9292

9393
- `useStaticQuery` does not accept variables (hence the name "static"), but can be used in _any_ component, including pages
9494
- Because of how queries currently work in Gatsby, Gatsby supports only a single instance of `useStaticQuery` in a file
95+
96+
## Other limitations
97+
98+
### Must be in `src` directory
99+
100+
`useStaticQuery` must be used in files that are nested below your site's top-level `src` directory. For example:
101+
102+
`useStaticQuery` works in these files:
103+
104+
- `<SITE_ROOT>/src/my-page.js`
105+
- `<SITE_ROOT>/src/components/my-component.js`
106+
107+
`useStaticQuery` **does not** work in these files:
108+
109+
- `<SITE_ROOT>/other-components/other-component.js`
110+
- `<SITE_ROOT>/other-library/other-component.js`

docs/docs/reference/built-in-components/gatsby-slice.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ export const query = graphql`
9999

100100
## Restrictions on using `<Slice>` placeholder
101101

102+
### Must be in `src` directory
103+
104+
Slice placeholders must be used in files that are nested below your site's top-level `src` directory. For example:
105+
106+
Slice placeholders work in these files:
107+
108+
- `<SITE_ROOT>/src/my-page.js`
109+
- `<SITE_ROOT>/src/components/my-component.js`
110+
111+
Slice placeholders **do not** work in these files:
112+
113+
- `<SITE_ROOT>/other-components/other-component.js`
114+
- `<SITE_ROOT>/other-library/other-component.js`
115+
102116
### Nested Slices
103117

104118
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.

0 commit comments

Comments
 (0)