![](/img/trans.png)
[英]Typescript - Argument of type 'string | (string | null)[]' is not assignable to parameter of type 'string'
[英]ReactJS Typescript Argument of type '{ keyPrefix: string; }' is not assignable to parameter of type string
對此只有幾個類似的問題,並且它們中的解決方案都不適用於我的情況。 這是給出此錯誤的代碼片段:
主頁.tsx 文件:
export const CTASection = () => {
const {t, i18n} = useTranslation( {keyPrefix:("homepage.ctaSection")} )
return (
<StyledSection>
<CTAContainer>
<Header>{t('Header')}</Header>
<Subtitle>
Play and learn <i>risk-free</i>. Prove your knowledge, speculate and
win!
</Subtitle>
.....
我的 JSON 文件:
[
{
"homepage": {
"ctaSection": {
"header": "some thing"
}
}
}
]
我實際上正在嘗試使用 JSON 文件的此內容顯示在 header 部分的主頁上,而我實際上得到的是錯誤。
根據Doc ,該選項位於第二個參數上。
const { t } = useTranslation('', { keyPrefix: 'homepage.ctaSection' });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.