score:0

you can not chain axios requests one to another, you need to make a seperate request per api resource you want to get, here is how you can get 2 requests in the same component

useeffect(() => {
    const requestoptions = {
        method: "get",
        headers: {
            "content-type": "application/json",
            authorization:json.parse(localstorage.getitem("tokentype")) + " " + json.parse(localstorage.getitem("accesstoken")),
        },
    };
    axios
        .get("/users", requestoptions)
        .then((response) => {
            setusers(response.data);
            setisloading(true);
        })
    .catch((err) => alert(err));

     axios
        .get("/groups", requestoptions)
        .then((response) => {
            setrenderedusers(response.data);
            setisloading(true);
        })
    .catch((err) => alert(err));
}, []);

score:1

you can use this pattern:

axios.all([requestone, requesttwo, requestthree]).then(axios.spread((...responses) => {
      const responseone = responses[0]
      const responsetwo = responses[1]
      const responesthree = responses[2]

      // use/access the results 

})).catch(errors => {
      // react on errors.

})

score:1

just use promise.all() here.

useeffect(() => {
    const requestoptions = {
        method: "get",
        headers: {
            "content-type": "application/json",
            authorization:json.parse(localstorage.getitem("tokentype")) + " " + json.parse(localstorage.getitem("accesstoken")),
        },
    };
    promise.all([
      axios.get("/users", requestoptions), 
      axios.get('/groups', requestoptions)
    ])
    .then(([usersresponse, groupsresponse]) => {
          setusers(usersresponse);
          setrenderedusers(groupsresponse);
          setisloading(true); // probably setloading(false) here?
      })
    .catch((err) => alert(err));
}, []);

score:1

the pattern to make multiple axios calls is like this:

axios.all([
    axios.get('http://google.com'),
    axios.get('http://apple.com')
  ])
  .then(axios.spread((googleres, appleres) => {
    // do something with both responses
  });

so your fixed example will be like this:

axios.all([
    axios.get("/users", requestoptions)
    axios.get("/groups", requestoptions)
  ])
  .then(axios.spread((usersres, groupsres) => {
      setusers(usersres.data);
      setrenderedusers(groupsres.data); // should it be users from groups? just set it to what you need
      setisloading(true);
    });


Related Query

More Query from same tag