簡體   English   中英

ReactJS Typescript 類型的參數 '{ keyPrefix: 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM