[英]On Clicking of Back Button, React Hooks State Not Change
const [detail, setDetail] = useState(false);
const [userDetail, setUserDetail] = useState();
useEffect(() => {
setSpinner(true);
userDetail(userId).subscribe((res) => {
if (res.status) {
history.push(`localhost:8000/user?userId=${res.id}`);
setUserDetail(res.data[0]);
**setDetail**(true);
setSpinner(false);
}
});
},[]);
const Details = (userId) => {
setSpinner(true);
userDetail(userId).subscribe((res) => {
if (res.status) {
history.push(`localhost:8000/user?userId=${res.id}`);
setUserDetail(res.data[0]);
setDetail(true);
setSpinner(false);
}
});
}
<button onClick ={() => Details(user_id)}>Display Details </button>
**detail** ? <div> User Name {name} </div> : <div> Temp User </div>
So, the main issue is after clicking on the button, then I click on the Back button the Url structure change but the State of function not change ie.所以,主要问题是点击按钮后,然后我点击后退按钮 Url 结构改变,但 function 的 State 没有改变。 setDetail .
设置详细信息。
Please help me with this as soon as possible请尽快帮我解决这个问题
const [detail, setDetail] = useState(false);
const [userDetail, setUserDetail] = useState();
useEffect(() => {
setSpinner(true);
userDetail(userId).subscribe((res) => {
if (res.status) {
history.push(`localhost:8000/user?userId=${res.id}`);
setUserDetail(res.data[0]);
**setDetail**(true);
setSpinner(false);
}
});
},[]);
const Details = (userId) => {
setSpinner(true);
userDetail(userId).subscribe((res) => {
if (res.status) {
history.push(`localhost:8000/user?userId=${res.id}`);
setUserDetail(res.data[0]);
setDetail(true);
setSpinner(false);
}
});
}
<button onClick ={() => Details(user_id)}>Display Details </button>
**detail** ? <div> User Name {name} </div> : <div> Temp User </div>
So, the main issue is after clicking on the button, then I click on the Back button the Url structure change but the State of function not change ie.所以,主要问题是点击按钮后,然后我点击后退按钮 Url 结构改变,但 function 的 State 没有改变。 setDetail .
设置详细信息。
Please help me with this as soon as possible请尽快帮我解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.