score:0

you moved the call to setheadlinks outside the function, and so the response variable is not in scope. just need to move it back inside:

useeffect(() => {
  const fetchdata = async () => {
    const response = await client.getentry(id);
    setheadlinks(response.fields.slug);
  };
  fetchdata();
}, []);

score:0

this is happening because response is defined inside the block of the async function. try defining response outside the async function scope to take advantage of closures.

useeffect(async () => {
  let response;
  const fetchdata = async () => {
    response = await client.getentry(id);
  };
  await fetchdata();
  setheadlinks(response.fields.slug);  
}, []);

take special notice that to do this you need to use let instead of const. you also have a problem with the use of async/await. see the corrected example and check the links below for more information about the topics mentioned.

https://developer.mozilla.org/en-us/docs/glossary/scope

https://developer.mozilla.org/es/docs/web/javascript/closures

https://developer.mozilla.org/en-us/docs/web/javascript/reference/statements/async_function

this should fix your current error, but i don't know if it is enough for what you are trying to do.


Related Query

More Query from same tag