diff --git a/node/README.md b/node/README.md new file mode 100644 index 0000000..7ec373b --- /dev/null +++ b/node/README.md @@ -0,0 +1 @@ +临时备份代码 \ No newline at end of file diff --git a/node/react-courses/chapter-fullstack-app.tsx b/node/react-courses/chapter-fullstack-app.tsx new file mode 100644 index 0000000..a9ddd2b --- /dev/null +++ b/node/react-courses/chapter-fullstack-app.tsx @@ -0,0 +1,71 @@ +import { PostEntity } from "@3rapp/api/modules/content/entities/post.entity"; +import { StyleProvider } from "@ant-design/cssinjs"; +import { Button, ConfigProvider, theme, App as AntdApp } from "antd"; +// import 'dayjs/locale/zh-cn'; +import zhCN from "antd/locale/zh_CN"; + +import axios from "axios"; +import { FC, useEffect, useState } from "react"; + +import $styles from "./app.module.css"; + +const getPosts = async () => { + let data: PostEntity[] = []; + try { + const res = await axios.get("/api/posts"); + data = res.data; + } catch (err) { + console.log("Error:", err); + } + return data; +}; + +const App: FC = () => { + const [data, setData] = useState([]); + useEffect(() => { + (async () => { + setData(await getPosts()); + })(); + }, []); + return ( + + + +
+
+ 欢迎来到3R教室,这是React课程第一节 + +

文章列表

+
    + {data.map((item) => ( +
  • {item.title}
  • + ))} +
+
+
+
+
+
+ ); +}; +export default App;