Reactjs React-TypeScript:React-markdown没有重载与此调用匹配

Reactjs React-TypeScript:React-markdown没有重载与此调用匹配,reactjs,typescript,markdown,Reactjs,Typescript,Markdown,如果需要,我很乐意移动到另一个库,但是react markdown似乎有很好的报告,但是,当我尝试在功能组件中将其与typescript一起使用时,我得到以下错误 import React from 'react'; import Markdown from 'react-markdown'; const Home: React.FC = () => { const getMarkdown = async () => { const markdown = await

如果需要,我很乐意移动到另一个库,但是react markdown似乎有很好的报告,但是,当我尝试在功能组件中将其与typescript一起使用时,我得到以下错误

import React from 'react';
import Markdown from 'react-markdown';

const Home: React.FC = () => {

  const getMarkdown = async () => {
    const markdown = await fetch('../markdown/home.md');
    const text = await markdown.text();
    return text;
  }
  const src = getMarkdown();

  return (    
      <div className='max-width'>
          <span className='body'>
            <Markdown source={src} />
          </span>
      </div>
  );
}

export { Home };
我得到的错误是

No overload matches this call.
  Overload 1 of 2, '(props: Readonly<ReactMarkdownProps>): ReactMarkdown', gave the following error.
    Type 'Promise<Response>' is not assignable to type 'string'.
  Overload 2 of 2, '(props: ReactMarkdownProps, context?: any): ReactMarkdown', gave the following error.
    Type 'Promise<Response>' is not assignable to type 'string'.  TS2769


你可以用钩子

const Home = () => {
const [text, setText] = useState(null);
  useEffect(() => {
     async function getText() {
         const markdown = await fetch('../markdown/home.md');
         const text = await markdown.text();
         setText(text);
     }
     getText();
  }, []);
  return (<div className='max-width'>
          <span className='body'>
            <Markdown source={text} />
          </span>
      </div>);
}

src是一个承诺,而不是字符串。感谢的Joseph我添加了一个等待,并得到了更多错误这当然清除了错误,但标记没有呈现。只需验证文本是否使用标记内容更新。当我记录文本时,我没有从home.md看到任何内容,而是从网站看到html,我猜标记文件的路径可能会改变可能是错误的,尝试使用一些在线降价文件CORS可能是一个问题如果我将降价文件夹移动到./public,然后链接到它,它会起作用,谢谢!