简体   繁体   中英

Problem with promise and create-react-app

I'm a bit new to react, so don't bully me hard. I got to solve this until tomorrow as my homework, and I thought you could help me with it.

Got a task which sounds like:

  1. Create a promise that returns data, must use create-react-app:
{
    "valid": true,
    "timestamp": 1582195447,
    "base": "USD",
    "rates": {
        "AED": 3.67338,
        "AFN": 77.8079,
        "ALL": 113.23065,
        "AMD": 478.14251
    }
}
  1. Display response in the list/table with flexBox

I am familiar with the flexbox tech, but I simply don't understand how to do part one. Despite I am familiar with promise/response in vanilla js, I know how to retrieve data from the API (like ships, planets, and stuff from starWarsApr for example), what I don't know is how to do it with this kind of object and with the usage of create-react-app.

Can you be so kind and maybe supply me with the link to materials about such staff, or to solve and explain to me how is this can be done. I don't have any friends front-end developers to explain to me such things, so I am sorry to ask.

Sincerely, I don't understand the goal of React in this exercice (maybe for ES6 setup).

The part one is quite simple, just create a Promise that returns the object asked for:

const promise = new Promise((resolve) => {
  resolve({
    valid: true,
    timestamp: 1582195447,
    base: 'USD',
    rates: {
      AED: 3.67338,
      AFN: 77.8079,
      ALL: 113.23065,
      AMD: 478.14251,
    },
  });
});

If you want to learn more about promises, check these links:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM