Skip to content

Commit

Permalink
Set jsxRuntime so that each component doesn't need to import from react
Browse files Browse the repository at this point in the history
No need for this import in every react component:
```javascript
import { useStaticQuery, graphql } from "gatsby";
```

You can still import from react if needed for hooks or other useful things

I like this because there's been a few times I didn't import react and was confused why
the component didn't render and my page broke

> Setting to automatic allows the use of JSX without having to import React.
> More information can be found on the (Introducing the new JSX Transform blog post)[https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html]
  • Loading branch information
eloisetaylor5693 committed Mar 6, 2025
1 parent 0008761 commit 3f94f68
Show file tree
Hide file tree
Showing 24 changed files with 9 additions and 27 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (!spaceId || !accessToken) {
}

module.exports = {
jsxRuntime: "automatic",
trailingSlash: "never",
siteMetadata: {
title: `Friends Of Foxley`,
Expand Down
1 change: 0 additions & 1 deletion src/components/bio.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { useStaticQuery, graphql } from "gatsby";

const Bio = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/deprecated-seo-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* See: https://www.gatsbyjs.com/docs/use-static-query/
*/

import * as React from "react";
import { memo } from "react";
import PropTypes from "prop-types";
import { Helmet } from "react-helmet";
import { useStaticQuery, graphql } from "gatsby";
Expand Down Expand Up @@ -68,4 +68,4 @@ DeprecatedSeoComponent.propTypes = {
title: PropTypes.string.isRequired,
};

export default React.memo(DeprecatedSeoComponent);
export default memo(DeprecatedSeoComponent);
4 changes: 2 additions & 2 deletions src/components/external-link.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react";
import { memo } from "react";

const ExternalLink = ({ href, children, ...rest }) => {
return (
Expand All @@ -8,4 +8,4 @@ const ExternalLink = ({ href, children, ...rest }) => {
);
};

export default React.memo(ExternalLink);
export default memo(ExternalLink);
1 change: 0 additions & 1 deletion src/components/find-us-on-facebook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { useStaticQuery, graphql } from "gatsby";
import * as style from "./find-us-on-facebook.module.css";
import ExternalLink from "./external-link";
Expand Down
1 change: 0 additions & 1 deletion src/components/hero-section.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { StaticImage } from "gatsby-plugin-image";
import * as style from "./hero-section.module.css";

Expand Down
1 change: 0 additions & 1 deletion src/components/layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { useStaticQuery, graphql } from "gatsby";
import * as style from "./layout.module.css";
import SiteHeader from "./site-header";
Expand Down
4 changes: 2 additions & 2 deletions src/components/site-footer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import { memo } from "react";
import * as style from "./site-footer.module.css";
import ExternalLink from "./external-link";

Expand Down Expand Up @@ -27,4 +27,4 @@ const SiteFooter = () => (
</footer>
);

export default React.memo(SiteFooter);
export default memo(SiteFooter);
4 changes: 2 additions & 2 deletions src/components/site-header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import { memo } from "react";
import { Link } from "gatsby";
import PropTypes from "prop-types";
import * as style from "./site-header.module.css";
Expand Down Expand Up @@ -34,4 +34,4 @@ SiteHeader.defaultProps = {
siteTitle: ``,
};

export default React.memo(SiteHeader);
export default memo(SiteHeader);
1 change: 0 additions & 1 deletion src/helpers/contentful-rendering-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GatsbyImage } from "gatsby-plugin-image";
import * as React from "react";

export const contentfulRenderingOptions = (className = null) => {
return {
Expand Down
1 change: 0 additions & 1 deletion src/pages/404.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";

import Layout from "../components/layout";
Expand Down
1 change: 0 additions & 1 deletion src/pages/contact.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../components/layout";
import DeprecatedSeoComponent from "../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/history.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../components/layout";
import DeprecatedSeoComponent from "../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql, Link } from "gatsby";
import Layout from "../components/layout";
import DeprecatedSeoComponent from "../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/news.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { Link, graphql } from "gatsby";

import Bio from "../components/bio";
Expand Down
1 change: 0 additions & 1 deletion src/pages/resources.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../components/layout";
import DeprecatedSeoComponent from "../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/trees.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql, Link } from "gatsby";
import Layout from "../components/layout";
import DeprecatedSeoComponent from "../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/trees/ancient-beech-tree-diversion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../../components/layout";
import DeprecatedSeoComponent from "../../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/trees/english-oak.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../../components/layout";
import DeprecatedSeoComponent from "../../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/trees/wych-elm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql } from "gatsby";
import Layout from "../../components/layout";
import DeprecatedSeoComponent from "../../components/deprecated-seo-component";
Expand Down
1 change: 0 additions & 1 deletion src/pages/wood-products.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { graphql, Link } from "gatsby";
import { StaticImage } from "gatsby-plugin-image";
import Layout from "../components/layout";
Expand Down
1 change: 0 additions & 1 deletion src/pages/work-days.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { Link, graphql } from "gatsby";

import Layout from "../components/layout";
Expand Down
1 change: 0 additions & 1 deletion src/templates/blog-post.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { Link, graphql } from "gatsby";

import Bio from "../components/bio";
Expand Down
1 change: 0 additions & 1 deletion src/templates/work-day-information.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from "react";
import { Link, graphql } from "gatsby";

import Bio from "../components/bio";
Expand Down

0 comments on commit 3f94f68

Please sign in to comment.