Redundant React Imports in next.js/examples
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
Currently most examples in the examples folder include react imports in files under pages which is not needed. I can’t recall if it ever was needed in Next.js (Perhaps some examples with an older next.js version need the imports)
Describe the solution you’d like
Remove react imports from files that don’t need. Method of testing is up to you to decide but I presume running the project, checking for console errors and making sure the functionality is the same should be sufficient?
Alternatives Considering whether the changes are worth it
Is this something that the Next.js team think should be changed? It’s perfectly reasonable if you guys think this isn’t worth the effort. With that said, I would love the honor of contributing to the Next.js repo, even with something that is probably considered a chore.
I don’t know if there are any technical differences with redundantly importing React but it could be argued that’s it’s bad practice.
Additional context
Some components are written with classes where as far as I can tell React imports are needed.
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import Link from 'next/link'
import { startClock, serverRenderClock } from '../actions'
import Examples from '../components/examples'
class Index extends PureComponent {
//...
}
Should those be updated to functional components or be left alone?
I also forked the repo just to showcase what the differences would be using the with-redux and with-redux-thunk examples. with-redux-thunk uses a class component in pages/index.js so there I didn’t remove the React import.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (11 by maintainers)
Top GitHub Comments
Next.js automatically adds the React import when JSX is used indeed. However keep in mind that we do still need to
import React from 'react'
when theReact
variable is used. Besides that yeah it seems like a good one to contribute 👍 Marked as good first issue.Exciting work! Thanks to all involved. FWIW, we get all notifications, so it’s no biggy!