I recently started using Gatsby and am having some troubles understanding some of the concepts (that might actually come from React).
For example: I am using a plugin for I18n called gatsby-plugin-intl and I am struggling to understand how I can fit the code from the documentation into my code.
My code I got from a starter package containts a file with code like this at src/pages/index.js:
import React from "react";
class RootIndex extends React.Component {
render() {
return (
...
But very often, I encounter code examples that start like this:
import React from "react"
const RootIndex = () => {
return (
...
Apparently, both approaches produce the same output. But when I am confronted with a tutorial telling me to implement code like this:
import React from "react"
import { injectIntl, Link, FormattedMessage } from "gatsby-plugin-intl"
const RootIndex = ({ intl }) => {
return (
<Layout>
<SEO
title={intl.formatMessage({ id: "title" })}
/>
...
I have no idea where to put the argument intl using the first approach defining a class. This does not work
import React from "react";
import { injectIntl, Link, FormattedMessage } from "gatsby-plugin-intl"
class RootIndex extends React.Component {
render({ intl }) {
return (
<Layout>
<SEO
title={intl.formatMessage({ id: "title" })}
/>
...
I hope that my description and issue is clear. I am missing knowledge to be more concise here. Which would be the right way to go?