'how to fix warning possible Unhandled promise rejection (id 0) react native

this warning show in emulator this warning show in console

and here my code how to fix this problem

CreateAdmin = (credentials) => {
    console.log('im here');
    try{ 
        fetch("api/url", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            Accept: "application/json"
        },
          body: JSON.stringify(credentials)
    }).then(data => data.json());

    } catch{
        console.log("Api call error");
    }
}



handleCreateAdmin = async () => {
    
    console.log('stay here handleCreateAdmin');
    const displayName = this.state.displayName;
    const username = this.state.username;
    const password = this.state.password;

    
    const response = await CreateAdmin({
        displayName,
        username,
        password
    });
    
    console.log(displayName,username,password);
    console.log(response);
    if(response.success){
        alert("success");
    }

}

and the second question is How can I send the image to the api and store the image in the database and display it back in the front-end? like message chat thank for help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source