Javascript react js中使用的oicd客户端中的重新渲染过多

Javascript react js中使用的oicd客户端中的重新渲染过多,javascript,html,reactjs,Javascript,Html,Reactjs,我在我的react应用程序中使用oidc客户端,我的应用程序多次重新渲染,这导致我的浏览器在多次重新渲染时停止响应,我在getUser方法中设置了警报,该方法在oidc客户端中的get user之后运行,但每次运行时,我都不知道我的问题是哪里有人可以帮助我? 这是我的密码: App.js import React,{useState,useffect,Fragment}来自'React'; 导入'/ie.polyfills'; 从“react Router dom”导入{BrowserRoute

我在我的react应用程序中使用oidc客户端,我的应用程序多次重新渲染,这导致我的浏览器在多次重新渲染时停止响应,我在getUser方法中设置了警报,该方法在oidc客户端中的get user之后运行,但每次运行时,我都不知道我的问题是哪里有人可以帮助我? 这是我的密码: App.js

import React,{useState,useffect,Fragment}来自'React';
导入'/ie.polyfills';
从“react Router dom”导入{BrowserRouter,BrowserRouter as Router};
从“./Routes/Routes”导入路由;
从“./Layout/Header/Header”导入标题;
从“./Layout/Footer/Footer”导入页脚;
从“./Layout/SideBar/SideBar”导入侧栏;
从“clsx”导入clsx;
从“./i18n/index”导入{I18nProvider,LOCALES};
从“./Components/CustomContext/CustomContext”导入{CustomProvider};
从“./Components/FindDirection/FindDirection”导入FindDirection;
从“/Pages/Providers/AuthProvider”导入{AuthConsumer,AuthProvider}”;
从“react responsive”导入{useMediaQuery}
//风格
从'@material ui/core/styles'导入{createMuiTheme};
从'@material ui/styles'导入{ThemeProvider};
导入“/App.scss”;
导出默认函数App(){
const[location,setLocation]=useState(window.location.pathname.trim());
const[open,setOpen]=useState(true);
const[lang,setLang]=useState(“fa-ir”);
const[direction,setDirection]=useState(FindDirection(lang));
const[theme,setTheme]=useState(createMuiTheme({
方向:FindDirection(lang),
}));
const[flag,setFlag]=使用状态(false);
const[user,setUser]=useState(null);
const isTabletOrMobile=useMediaQuery({query:'(最大宽度:768px)});
常量openSideBar=()=>{
setOpen(!open);
}
//从url获取本地语言
useffect(()=>{
让_lang=location.split('/')[1];
Object.keys(区域设置)
.filter(键=>{
如果(键===\u lang){
log('key:',key);
//警报(键);
塞特朗(钥匙);
}
});
},[窗口位置];
useffect(()=>{
setDirection(FindDirection(lang));
},[lang]);
useffect(()=>{
如果(用户=={}){
setFlag(假);
}
否则{
setFlag(真);
}
},[用户];
//处理更改语言
函数handleChangeLang(e、val、oldLang){
设_lasLocation=位置;
_更换(奥德朗,瓦尔);
设置位置(_lasLocation.replace(oldLang,val));
Object.keys(区域设置)
.filter(键=>{
如果(键===val){
塞特朗(钥匙);
window.location=window.location.origin+\u lasLocation.replace(oldLang,val);
}
});
}
//方向
useffect(()=>{
如果(方向=='rtl'){
document.getElementsByTagName('body')[0].style.direction=“rtl”;
}
否则{
document.getElementsByTagName('body')[0].style.direction=“ltr”;
}
},[lang]);
返回(
{
({getUser})=>{
console.log('user:',user);
如果(!标志){
getUser()。然后(结果=>{
if(结果!==未定义和结果!==空){
返回;
}
设置用户(结果);
setFlag(真);
});
}
返回(
{/*头*/}
{/*侧边栏*/}
{isTabletOrMobile?:
}  
{/*内容*/}
{/*页脚*/}
);
}
}
);
}