【发布时间】:2020-02-17 08:30:13
【问题描述】:
如果需要,我很乐意转移到另一个库,但是 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
【问题讨论】:
-
src是一个承诺而不是一个字符串。 -
谢谢约瑟夫,我添加了一个等待并得到更多错误
标签: reactjs typescript markdown