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?
Reactin scope when using JSX because the compiled code referencesReact. The description of that rule also answers your question. The react/jsx-uses-react rule preventsReactfrom being marked as unused. - Ross Allen