json "{ keyPrefix:string; }“类型的ReactJS Typescript参数不可分配给string类型的参数

rxztt3cl  于 2023-11-20  发布在  React
关注(0)|答案(2)|浏览(94)

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


的数据
homepage.tsx文件:

  1. export const CTASection = () => {
  2. const {t, i18n} = useTranslation( {keyPrefix:("homepage.ctaSection")} )
  3. return (
  4. <StyledSection>
  5. <CTAContainer>
  6. <Header>{t('Header')}</Header>
  7. <Subtitle>
  8. Play and learn <i>risk-free</i>. Prove your knowledge, speculate and
  9. win!
  10. </Subtitle>
  11. .....

字符串
我的JSON文件:

  1. [
  2. {
  3. "homepage": {
  4. "ctaSection": {
  5. "header": "some thing"
  6. }
  7. }
  8. }
  9. ]


实际上,我试图使用JSON文件的内容显示在主页的标题部分,我实际上得到的是错误。

wr98u20j

wr98u20j1#

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

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

字符串

mctunoxg

mctunoxg2#

请尝试以下操作:

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

字符串

相关问题