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

React18版本需要提示更新 #234

Closed
ZYyyh-cool opened this issue May 23, 2022 · 12 comments
Closed

React18版本需要提示更新 #234

ZYyyh-cool opened this issue May 23, 2022 · 12 comments

Comments

@ZYyyh-cool
Copy link

ZYyyh-cool commented May 23, 2022

import { Map,Marker} from '@uiw/react-amap';
使用Map就会提示
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more
希望能更新下React18版本
使用情况:

function App() {
  return (
    <Suspense fallback={<Spinner />}>
      <APILoader akay="">
            <Map 
             viewMode='3D'
             zoom='11.8'
             center={[10.126,30.236]}
             mapStyle= "amap://styles/darkblue"
             >
            </Map>
      </APILoader>
    </Suspense>
  );
}


const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
      <Provider store={store}>
        <App />
     </Provider>
);
@jaywcjlove
Copy link
Member

@jaywcjlove
Copy link
Member

// Before
import { render } from 'react-dom';
const container = document.getElementById('app');
render(<App tab="home" />, container);

// After
import { createRoot } from 'react-dom/client';
const container = document.getElementById('app');
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(<App tab="home" />);

@ZYyyh-cool 错误在于你 18 的 API使用

@ZYyyh-cool
Copy link
Author

@jaywcjlove 18 API使用没用问题,可以看看上面使用情况代码,注释掉Map组件没有报错,我再排查下

@ZYyyh-cool
Copy link
Author

我也测试了你的实例,也是没有问题

@jaywcjlove
Copy link
Member

jaywcjlove commented May 23, 2022

@ZYyyh-cool createRoot 倒入官方指定下面方式。ReactDOM.createRoot 是错误的吧

import { createRoot } from 'react-dom/client';

@ZYyyh-cool
Copy link
Author

尝试在Map组件里面添加Marker会报错,不确实是否能这样用,我看你们的官网网站是这样用的

<ScaleControl offset={[16, 30]} position="LB" />
<ToolBarControl offset={[16, 10]} position="RB" />
<ControlBarControl offset={[16, 180]} position="RB" />
<Geolocation
maximumAge={100000}
borderRadius="5px"
position="RB"
offset={[16, 80]}
zoomToAccuracy={true}
showCircle={true}
/>
<Marker title="北京市" position={new AMap.LngLat(116.405285, 39.904989)} />

@ZYyyh-cool
Copy link
Author

我换这种用法就没有报错了

{({ AMap, map, container }) => {
return;
}}

@HerbertHe
Copy link
Contributor

我也是添加Marker有报错

image

@HerbertHe
Copy link
Contributor

image

还有之前提到的类型不兼容的问题: #233

image

@jaywcjlove jaywcjlove pinned this issue Jun 2, 2022
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

No branches or pull requests

3 participants