const callAFunction = () => {
      if (AppState.currentState === 'background') {
        function1()
      }
    }
    useEffect(()=>{
AppState.addEventListener('change', callAFunction);
    },[])
    const function1 = () => {
      axios.get('/user_login', {
        params: {
          username: 'john1904',
        }
      })
        .then(function (response) {
          if (response.data.status === false) {
            function1()
          }
    
        })
    }
I am using this above function recursively. But as the app goes background function1 is calling again and again as still the function1() i have already called. So i want that function1() call every time as the app goes background. But in Async form as if function1() then it will not call it again.
So i am not able to get how can i do this in when app is in background so it will check if this function is running then don't run it other wise run it.
 
    