postor / next-i18n-helper

next 10 has i18n built in, so this project archived, for next 10 solution refer https://github.com/postor/next-i18n-loader. | next 10 已经支持多语言,所以这个项目存档,在 next 10 上的多语言方案可以参考 https://github.com/postor/next-i18n-loader
https://www.youtube.com/watch?v=npC7orrLsvE&list=PLM1v95K5B1ntVsYvNJIxgRPppngrO_X4s
7 stars 1 forks source link

Invalid hook call #7

Closed badris101 closed 4 years ago

badris101 commented 4 years ago

hooks can only be called inside the body of a function component

I had multiple instances of React ├┬ next-i18n-helper@1.0.27 └── react@16.13.1 └── react@16.12.0

postor commented 4 years ago

of course hooks can only be called inside the body of a function component, so are you using hooks outside function component? that does nothing to this lib

badris101 commented 4 years ago

no i m calling hooks corectly inside the body of function i think the problem similer to issue

badris101 commented 4 years ago

this is my code that expose the error:

`import React, { useState } from 'react' import translate from 'next-i18n-helper/dist/translate' import { i18nHelper } from 'components/i18n'

const translateNS = ['index']

const Header = () => { const [lang, setLang] = useState(i18nHelper.getCurrentLanguage())

const handleLang = (e) => {
    setLang(e.target.value)
    i18nHelper.setCurrentLanguage(e.target.value)
}

return (
    <select value={lang} onChange={handleLang}>
        <option value="en">English</option>
        <option value="fr">Frensh</option>
    </select>
)

}

const TranslatedHeader = translate(translateNS)(Header) TranslatedHeader.translateNS = translateNS

export default TranslatedHeader `

postor commented 4 years ago

I tried your code in my basic example with only changing import, it worked fine, so it's not problem of this lib, can you merge your logic to the examples, https://github.com/postor/next-i18n-helper/tree/master/examples