我正在尝试从 MongoDB 服务器获取注释数组 注释数组的示例如下所示
{
    "_id" : ObjectId("5f240b9ab414f1377c4155e0"),
    "title" : "Hello",
    "content" : "World !",
    "__v" : 0
}
/* 2 */
{
    "_id" : ObjectId("5f240d45b414f1377c4155e1"),
    "title" : "aaaaaaaaaa",
    "content" : "aaa",
    "__v" : 0
}
Run Code Online (Sandbox Code Playgroud)
现在函数 getNote 从 MongoDB 获取注释,然后使用 useState 我传递数组,现在我的问题是:我希望函数 getNote 在 React 页面加载时自动调用。下面是函数 getNote 的代码
function getNote() {
    axios
      .get("/")
      .then((response) => {
        setFinalNoteDB(response.data);
        
      })
      .catch((err) => {
        if (err) {
          console.log("error in app.jsx");
        }
      });
Run Code Online (Sandbox Code Playgroud)
通用app.jsx代码如下所示
import React, { useState, Component } from "react";
import …Run Code Online (Sandbox Code Playgroud)