CommentAnchor.tsx 793 B

123456789101112131415161718192021222324252627282930313233
  1. import { useEffect, useState } from "react";
  2. import { get } from "../../request";
  3. import { ICommentAnchorResponse } from "../api/Comment";
  4. import MdView from "../template/MdView";
  5. import AnchorCard from "./AnchorCard";
  6. interface IWidget {
  7. id?: string;
  8. }
  9. const CommentAnchorWidget = ({ id }: IWidget) => {
  10. const [content, setContent] = useState<string>();
  11. useEffect(() => {
  12. if (typeof id === "string") {
  13. get<ICommentAnchorResponse>(`/v2/discussion-anchor/${id}`).then(
  14. (json) => {
  15. console.log(json);
  16. if (json.ok) {
  17. setContent(json.data);
  18. }
  19. }
  20. );
  21. }
  22. }, [id]);
  23. return (
  24. <div>
  25. <AnchorCard>
  26. <MdView html={content} />
  27. </AnchorCard>
  28. </div>
  29. );
  30. };
  31. export default CommentAnchorWidget;