StackOverflow - StackOverflow

ESLint: 'React' is defined but never used.(no-unused-vars) when using JSX pragma

I had a similar problem exporting only a styled component. I wrapped it in <React.Fragment> and exported that instead.

Before:

import React from 'react';
import styled from '@emotion/styled';

export const LabelText = styled.span`
  font-size: 0.75em;
  font-weight: 500;
`;

After:

import React from 'react';
import styled from '@emotion/styled';

const StyledSpan = styled.span`
  font-size: 0.75em;
  font-weight: 500;
`;

export const LabelText = ({ children }) => (
  <React.Fragment>
    <StyledSpan>{children}</StyledSpan>
  </React.Fragment>
);

Was this helpful?

Have a different question?

Can't find the answer you're looking for? Submit your own question to our community.

🛎️ Get Weekly OTA Fixes

New answers, vendor issues, and updates — straight to your inbox.