question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid hook call error when using withTranslation in class component

See original GitHub issue
class PageTitle extends React.Component {
  render() {
    const { t } = this.props;
    return (
      <div>
        {t(pageTitle)}
      </div>
    );
  }
}

PageTitle.propTypes = {};

export default withTranslation('common')(PageTitle);

Screenshot 2021-03-12 at 12 14 48 PM

Somehow when i try to use withTranslation in a class component, it will throw a hooks related error

My package version “next”: “10.0.6” “next-translate”: “^1.0.2”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
RandomDude123commented, Mar 16, 2021

np. consider using TS as well as move away from class components 😃 maybe you can close this github issue yourself?

1reaction
richardhsuehcommented, Mar 16, 2021

Oh, my bad. I missed that part.😓 The error is gone now. I guess I am too used to react-i18next’s API 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid hook call in react. I am using class component
I am using withTranslation() in my react class component at the last line when I am exporting my application. But it is giving...
Read more >
Invalid Hook Call Warning - React
You are probably here because you got the following error message: Hooks can only be called inside the body of a function component....
Read more >
Invalid hook call with next-i18nnext · Issue #611 - GitHub
Describe the bug Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for...
Read more >
Invalid hook call in react. I am using class component-Reactjs
Coding example for the question Invalid hook call in react. I am using ... import { withTranslation } from "react-i18next"; class MyComponent extends...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Hooks can only be called inside of the body of a function component. in my react native app I have started playing with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found