question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting odd ESLint warnings when creating custom components for mdx template...

See original GitHub issue

I am a bit perplexed…I’m making some custom components for an mdx template following the examples in the tutorial, like so:

const P = props =>
  <p
    {...props}
    style={{
      gridColumn: '2/3',
      fontFamily: 'Avenir Next',
      color: 'white',
      fontSize: 'calc(18px + (24 - 18) * ((100vw - 300px) / (1600 - 300)))',
      lineHeight: 2,
      fontWeight: '300'
    }} 
  />

…but I’m getting this odd lint warning for each component I create in this fashion:

warn ESLintError: 
/Users/rchrdnsh/Documents/Code/Gatsby/RYKR/src/templates/article.js
  185:3  warning  Headings must have content and the content must be accessible by a screen reader
jsx-a11y/heading-has-content
  196:3  warning  Headings must have content and the content must be accessible by a screen reader
jsx-a11y/heading-has-content
  207:3  warning  Headings must have content and the content must be accessible by a screen reader
jsx-a11y/heading-has-content
  218:3  warning  Headings must have content and the content must be accessible by a screen reader
jsx-a11y/heading-has-content
  229:3  warning  Headings must have content and the content must be accessible by a screen reader

…so i don’t know what’s going on here, and would love to get rid of these warnings, but is there an issue with mdx or what i’m doing that I am unaware of?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ascorbiccommented, Dec 19, 2019

OK, that would be it. If you change your code to e.g.

const H1 = ({children, ...props}) =>
  <h1
    {...props}
    style={{
      gridColumn: '2/3',
      fontFamily: 'Oswald',
      fontSize: 'calc(32px + (48 - 32) * ((100vw - 300px) / (1600 - 300)))',
      color: 'white'
    }}
  >{children}</h1>

then it should fix it.

If you want to define the components in another file it’s quite simple: you just need to export them from that file:

// src/components/DesignSystem.js

export const H1 = ({children, ...props}) =>
  <h1
    {...props}
    style={{
      gridColumn: '2/3',
      fontFamily: 'Oswald',
      fontSize: 'calc(32px + (48 - 32) * ((100vw - 300px) / (1600 - 300)))',
      color: 'white'
    }}
  >{children}</h1>

// ...

…and then import them into your component:

// src/templates/article.js

import { H1, H2, H3, H4, P } from "../components/DesignSystem";

const components = {
  h1: H1,
  h2: H2,
  h3: H3,
  h4: H4,
  h5: H5,
  h6: H6,
  p: P
}

// ...and then the rest of the file as before

We could probably do with updating the documentation to show the use of { children }.

0reactions
rchrdnshcommented, Jan 9, 2020

hmmmmm…i think this got solved, so i’ll close for now…i think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a custom lint rule for Markdown and MDX using ...
How to create a custom lint rule for Markdown and MDX using remark and ESLint · Contents · Set up the project ·...
Read more >
Common React TypeScript ESLint / Lint Errors & Warning ...
Not specifying attributes in certain components can produce lint error messages. For example, a button needs the button type and lists in React...
Read more >
Troubleshooting MDX
This article goes through several common problems and errors that might occur when using MDX.
Read more >
Gatsby i18n: A Hands-on Guide | Phrase
Hit the ground running quickly with this Gatsby i18n tutorial and learn how to add internationalization support to your Gatsby project.
Read more >
@storybook/addon-actions | Yarn - Package Manager
@storybook/addon-actions. owner storybookjs16.7mMIT6.5.15TS vulns 0 vulnerabilities. Get UI feedback when an action is performed on an interactive element.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found