본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

React 19 호환성

원문 보기 위키 갱신

React 19 호환성 (React 19 Compatibility)

antd-mobile v5는 기본적으로 React 16 ~ 18과 호환돼요. React 19에서는 아래의 호환성 방법을 사용해 적응할 수 있어요. 이 호환성 방법과 인터페이스는 다음 메이저 버전에서 제거될 예정이에요.

출처: 문서

본문

React 19 호환성 이슈

React 19가 react-dom의 export 방식을 조정했기 때문에, antd-mobile은 ReactDOM.render 메서드를 직접 사용할 수 없어요. 그래서 antd-mobile을 사용하면 다음 문제에 부딪힐 수 있어요:

  • React 19 RC react-dom no longer exports createRoot #6635
  • Toast not supported in the latest React version #6842
  • Uncaught (in promise) TypeError: reactRender is not a function #6814

따라서 antd-mobile이 React 19에서 정상 동작하도록 호환성 설정을 사용해야 해요.

호환성 방법

unstableSetRender

unstableSetRender는 저수준 등록 메서드로, 개발자가 ReactDOM의 렌더링 방식을 수정할 수 있게 해 줘요. 애플리케이션의 진입점에 다음 코드를 작성해 주세요:

import { unstableSetRender } from 'antd-mobile'; // Support since version ^5.40.0
import { createRoot } from 'react-dom/client';

unstableSetRender((node, container) => {
  container._reactRoot ||= createRoot(container);
  const root = container._reactRoot;
  root.render(node);
  return async () => {
    await new Promise((resolve) => setTimeout(resolve, 0));
    root.unmount();
  };
});

더 알아보기

antd-mobile 활용 가이드는 요청 시 불러오기 문서도 참고해 보세요.