ReactJS Typescript 类型参数 '{ keyPrefix: string; }' 不可分配给字符串类型的参数

问题描述 投票:0回答:2

只有几个类似的问题,这两个问题的解决方案在我的情况下都不起作用。这是给出此错误的代码片段:

homepage.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 文件的此内容显示在主页的标题部分中,而我实际上得到的是错误。

javascript reactjs json typescript i18next
2个回答
2
投票

根据Doc,该选项位于第二个参数上。

const { t } = useTranslation('', { keyPrefix: 'homepage.ctaSection' });


0
投票

尝试以下操作:

const { t } = useTranslation('homepage', { keyPrefix: 'ctaSection' });
© www.soinside.com 2019 - 2024. All rights reserved.