gist/react-courses/chapter-fullstack-app.tsx
2024-05-11 03:35:57 +08:00

72 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<PostEntity[]>([]);
useEffect(() => {
(async () => {
setData(await getPosts());
})();
}, []);
return (
<ConfigProvider
locale={zhCN}
theme={{
algorithm: theme.defaultAlgorithm,
token: {
colorPrimary: "#00B96B",
},
components: {
Layout: {
colorBgBody: "",
},
},
}}
>
<StyleProvider hashPriority="high">
<AntdApp>
<div className={$styles.app}>
<div className={$styles.container}>
3R教室<span>React课程第一节</span>
<Button
type="primary"
className="!bg-lime-400 !text-emerald-900"
href="https://pincman.com/3r"
target="_blank"
>
</Button>
<h2></h2>
<ul>
{data.map((item) => (
<li key={item.id}>{item.title}</li>
))}
</ul>
</div>
</div>
</AntdApp>
</StyleProvider>
</ConfigProvider>
);
};
export default App;