Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React imports 2 #7463

Merged
merged 3 commits into from
Mar 7, 2025
Merged

React imports 2 #7463

merged 3 commits into from
Mar 7, 2025

Conversation

zoran995
Copy link
Collaborator

@zoran995 zoran995 commented Feb 13, 2025

What this PR does

Fixes: #7514
Supersedes the #7347, created new PR so build and deployment are available for testing
Small step toward #6538
Run upgrade-react-imports codemod to update react imports so they can work in react 17/18. Partially supersedes #7051.

Don't worry about merge conflicts first PR is only changes by codemod so it is easy to recreate

Test me

Tested locally yarn gulp build. All tests passes. Running the app locally works

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@pjonsson
Copy link
Contributor

I don't see any version updates in this PR, so I'm guessing a corresponding PR in the TerriaMap repository can be merged independently of this PR?

@zoran995
Copy link
Collaborator Author

zoran995 commented Mar 5, 2025

@ljowen I have rebased this after the latest UI changes.

@zoran995 zoran995 merged commit 0036f62 into main Mar 7, 2025
9 checks passed
@zoran995 zoran995 deleted the react-imports-2 branch March 7, 2025 10:02
@pjonsson
Copy link
Contributor

pjonsson commented Mar 7, 2025

@zoran995 I hadn't looked at the details of this PR but I just did a git grep "React\." on latest main and there are still quite a few hits. Will things work as intended despite removing the React import?

@zoran995
Copy link
Collaborator Author

zoran995 commented Mar 7, 2025

The React team recommends using named imports, which works because of automatic JSX support in Babel and TypeScript. When using automatic JSX, Babel and TypeScript detect the JSX syntax in the file and add import React from "react" in the background. Things like React.ReactNode, React.FC, and similar are only types that work in TypeScript due to automatic JSX so TypeScript knows about them without explicit imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert react imports to use automatic jsx and named imports
3 participants