简体   繁体   English

promise 和 create-react-app 的问题

[英]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:创建一个返回数据的promise,必须使用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使用 flexBox 在列表/表格中显示响应

I am familiar with the flexbox tech, but I simply don't understand how to do part one.我熟悉 flexbox 技术,但我根本不明白如何做第一部分。 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.尽管我熟悉 vanilla js 中的承诺/响应,但我知道如何从 API 中检索数据(例如来自 starWarsApr 的船舶、行星和东西),但我不知道如何使用这种object 并使用 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).真诚地,我不明白 React 在这个练习中的目标(可能是 ES6 设置)。

The part one is quite simple, just create a Promise that returns the object asked for:第一部分非常简单,只需创建一个Promise并返回 object 要求:

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:如果您想了解有关 Promise 的更多信息,请查看以下链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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