【发布时间】:2019-09-29 06:07:59
【问题描述】:
当 API 请求返回 401 并将用户发送到登录屏幕时,我收到以下警告:
Warning: Can't perform a React state update on an unmounted component.
在使用钩子的功能组件中处理此警告的最佳方法是什么。请看下面的代码:
.
.
export default function MovieDetailsScreen() {
const [movie, setMovie] = useState({});
const movieId = useNavigationParam('movieId');
useEffect(() => {
// This is the method that does the request and returns 401 (It
// uses the fetch library)
Client.movies.show(movieId)
.then(result => {
setMovie(result)
})
}, [])
.
.
.
【问题讨论】:
标签: react-native expo