Integrating RapidAPI with React Native application

I’m working on a React Native app and I’m having trouble getting RapidAPI to work properly. My app used to fetch user information from a simple JSON endpoint like this:

async loadUserData() {
  try {
    const result = await fetch('mysite.com/userinfo.json');
    const userData = await result.json();
    this.setState({
      loading: false,
      users: userData,
    });
  }
  catch (err) {
    console.log(err);
  }
}

I want to switch to RapidAPI for better security but my current attempt just shows a blank screen:

async loadUserData() {
  try {
    const result = await fetch('dice-roll-api.p.rapidapi.com/roll', {
      "method": "GET",
      "headers": {
        "x-rapidapi-host": "mysite.com",
        "x-rapidapi-key": 'abc123def456ghi789jkl012mno345pqr678stu901vwx234yz'
      }
    });
    const userData = await result.json();
    this.setState({
      loading: false,
      users: userData,
    });
  }
  catch (err) {
    console.log(err);
  }
}

What am I doing wrong here? The app worked fine before but now it’s not loading any data at all.

you’re mixing up your endpoints. you’re calling the dice-roll API but setting x-rapidapi-host to mysite.com - that doesn’t make sense. the host header needs to match the actual API you’re calling, so it should be “dice-roll-api.p.rapidapi.com” not your old site.

This goes way beyond just an endpoint issue. You’re using RapidAPI for security but switched from user data to dice rolls - that makes zero sense for what you’re trying to do. If you want user data, find an actual user/profile API on RapidAPI instead of the dice one. Also, make sure you’re using https:// in your fetch URL since RapidAPI requires SSL. I’d add some debugging - log the response status and headers before parsing JSON so you can see what’s actually coming back.

You switched from a user info endpoint to a dice roll API but didn’t update your data handling. The dice API returns something like {“result”: 6}, while your setState still expects ‘users’ data. Either find a proper user data API on RapidAPI or update your component to handle dice roll responses. Also check your network tab - you might have CORS errors or 401 auth failures that your catch block isn’t showing.