Do I need to import React for stateless functional components?

Viewed 9348

All around me (e.g. blog posts, code) I see code for React stateless functional components in which React is imported even though it's never used.

import React from 'react';

function MyComponent() {
  return <div>Howdy!</div>;
}

export default MyComponent;

I'm wondering why we need to import React when it's not actually used (in any explicit manner).

I'm also surprised that my linter doesn't complain about the un-used import.

Is there some reason to import React into functional components that I'm not aware of?

4 Answers

No, you don't need to, React 17 does it automatically with the help of out of the box JSX Transform.

Find this article here

Related