相关疑难解决方法(0)

Using async/await inside a React functional component

I'm just beginning to use React for a project, and am really struggling with incorporating async/await functionality into one of my components.

I have an asynchronous function called fetchKey that goes and gets an access key from an API I am serving via AWS API Gateway:

const fetchKey = async authProps => {
  try {
    const headers = {
      Authorization: authProps.idToken // using Cognito authorizer
    };

    const response = await axios.post(
      "https://MY_ENDPOINT.execute-api.us-east-1.amazonaws.com/v1/",
      API_GATEWAY_POST_PAYLOAD_TEMPLATE,
      {
        headers: headers
      }
    );
      return response.data.access_token; …
Run Code Online (Sandbox Code Playgroud)

javascript async-await reactjs material-ui

4
推荐指数
2
解决办法
1829
查看次数

标签 统计

async-await ×1

javascript ×1

material-ui ×1

reactjs ×1