![](/img/trans.png)
[英]I receive a 401 error from the server when trying to authenticate a user in my React Native app on Android
[英]React Native detect when user is trying to quit the app?
I want to update my redux state based on the component unmount but in case a user terminates the app how to detect that and update my redux state based on the app termination as the componentWillUnmount will not be called in case of quitting the app. 有沒有辦法在本機反應中檢測應用程序終止(未暫停)?
import React from "react"; export default class Clock extends React.Component { constructor(props) { console.log("Clock", "constructor"); super(props); this.state = { date: new Date() }; } tick() { this.setState({ date: new Date() }); } // These methods are called "lifecycle hooks". componentDidMount() { console.log("Clock", "componentDidMount"); this.timerID = setInterval(() => { this.tick(); }, 1000); } // These methods are called "lifecycle hooks". componentWillUnmount() { console.log("Clock", "componentWillUnmount"); clearInterval(this.timerID); } render() { return ( <div>It is {this.state.date.toLocaleTimeString()}.</div> ); } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.