相关疑难解决方法(0)

useEffect not called in React Native when back to screen

How are you. This is scenario of this issue. Let's say there are 2 screens to make it simple.

  1. enter A screen. useEffect of A screen called.
  2. navigate to B screen from A screen
  3. navigate back to A screen from B. at this time, useEffect is not called.

    function CompanyComponent(props) {
    
       const [roleID, setRoleID] = useState(props.user.SELECTED_ROLE.id)
    
       useEffect(()=>{ 
    
     // this called only once when A screen(this component) loaded,  
     // but when comeback to this screen, it doesn't called
       setRoleID(props.user.SELECTED_ROLE.id)
     }, [props.user]) …
    Run Code Online (Sandbox Code Playgroud)

reactjs react-native use-effect

33
推荐指数
5
解决办法
2万
查看次数

标签 统计

react-native ×1

reactjs ×1

use-effect ×1