An explanation of changes between React 17 and 18.
Join DevzConnect — where devs connect, code, and level up together. Got questions? Stuck on a bug? Or just wanna help others crush it? Jump in and be part of a community that gets it
Welcome back to DevzConnect — where devs connect, code, and level up together. Ready to pick up where you left off? Dive back in, ask questions, share wins, or help others crush their goals!
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
React 17 and React 18 introduced several differences, particularly with regard to features, performance improvements, and changes to the way React works under the hood. Here’s a comparison between the two:
1. Concurrent Rendering (React 18)
React 17: React 17 did not have support for concurrent rendering. The rendering process was synchronous, meaning React rendered the entire component tree in one go, blocking the UI thread until the render process was completed.
React 18: React 18 introduces concurrent rendering as an opt-in feature. This allows React to work on multiple tasks simultaneously, making the UI more responsive and improving the user experience. With concurrent rendering, React can interrupt rendering to keep the UI interactive while it continues to update in the background.
ReactDOM.createRoot
: In React 18, you now need to useReactDOM.createRoot
instead ofReactDOM.render
to enable concurrent features.2. Automatic Batching (React 18)
setTimeout
or promises).setTimeout
,Promises
, etc.), which means React will group updates together and minimize unnecessary re-renders, improving performance.3. Suspense and Suspense List (React 18)
4. Server-Side Rendering (SSR) and Hydration (React 18)
5.
useId
Hook (React 18)React 17: No built-in hook for generating unique IDs.
React 18: React 18 introduces the
useId
hook to generate stable, unique IDs that are safe for use in both the client and server during SSR. This is helpful in preventing mismatches between server-rendered and client-rendered IDs, especially in forms and elements requiring IDs.6. Concurrent Features and
startTransition
(React 18)React 17: Did not have concurrent features like
startTransition
.React 18: React 18 introduces the
startTransition
API to mark updates as non-urgent, helping React prioritize more important updates (e.g., user interactions). This allows for smoother rendering of lower-priority updates, such as state updates triggered by network responses or other non-urgent updates.7. Gradual Adoption of New Features (React 18)
Suspense
for data fetching, and improved SSR. However, it also allows for gradual adoption of these features. This means you can opt into concurrent rendering and other new features on a per-component basis, making it easier to adopt them over time.8. Improved TypeScript Support
useId
and other new APIs.9. Legacy Features and Backward Compatibility
createRoot
instead ofrender
).10. React 18 New APIs and Features
ReactDOM.createRoot
: As mentioned, you need to use this method for initializing the React app, enabling concurrent rendering.useTransition
: A new hook for handling transitions.startTransition
: Used for prioritizing urgent updates over non-urgent ones.useId
: A new hook for generating unique IDs.Summary of Key Differences:
createRoot
)SuspenseList
useId
HookstartTransition
)Conclusion:
React 18 introduces significant performance improvements with concurrent rendering, automatic batching, and features for smoother user experiences, such as
Suspense
for data fetching. It’s an opt-in upgrade, meaning you don’t need to switch everything over at once but can adopt features gradually. React 17 was more about making React easier to upgrade, whereas React 18 focuses on improving how React works behind the scenes.