我收到错误:
“Element”类型中缺少属性“default”,但类型中需要属性“default”
'{ 默认:组件类型; }'.ts(2322)
{React.lazy(() => import(`../../i18n/locales/${this.props.lang}`).then(o => (
<CustomSelects
options={o.option}
formattedMessageId="createroom_genre"
value={this.props.genre}
handleValueChange={this.handleGenreChange}
/>
))) }
I read 将 React.lazy 与 TypeScript 结合使用 https://stackoverflow.com/questions/54150819/using-react-lazy-with-typescript但是,我不知道在我的情况下该怎么做。
如果您需要更多信息,请告诉我。
谢谢。
组件不应在使用它们的地方就地声明,这可能会破坏优化并可能导致无限循环。
React.lazy
旨在与动态一起使用import
,回调函数应该返回模块的承诺,即{ default: Component }
对象,但它当前返回 React 元素的承诺。
React.lazy
无意参数化,它不接受 props 和this.props.lang
不能在那里工作。它应该用另一个组件包装来接收道具:
const LocalCustomSelects = React.memo(({ lang }) => {
const Lazy = React.lazy(async () => {
const o = await import(`../../i18n/locales/${lang}`);
return { default: props => <CustomSelects ... /> };
});
return <Lazy/>;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)