react 组件挂载两次

使用版本
{
"react": "^18.1.0",
"react-app-polyfill": "^3.0.0",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.1.0",
"react-refresh": "^0.11.0",
"react-router-dom": "^6.3.0",
}
问题:
所有组件在路由跳转的时候都会挂载两次,导致请求数据也是两遍,排查问题

问题所在:

index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.scss';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
 root.render(
    
         
     
);
reportWebVitals();

改成

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.scss';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render();
reportWebVitals();

问题解决

你可能感兴趣的:(react 组件挂载两次)