2

I am still getting hang of React js. I am trying to export multiple components and i am getting this error "Identifier 'withN' has already been declared" Here is my code for export

const withN =  withNamespaces()(App)
export default connect(
  mapStateToProps,
  { logOut }
)(withRouter(Header));

Here is my import code

import { withN } from 'react-i18next';

Please tell me what is wrong.

Thanks update: After correcting my export statement as suggested by @octobus, I get this error attached in the image props undefined

user918204
  • 57
  • 2
  • 7

1 Answers1

1

You can't import something and reassign a value to it. The reason you are getting the error is that there is already a declaration of withN.

jarmod
  • 71,565
  • 16
  • 115
  • 122
octobus
  • 1,246
  • 1
  • 14
  • 20
  • This is incorrect, imports are read-only views of the exported-values – Hamza El Aoutar Oct 16 '19 at 12:52
  • When i do that I get "withNamespaces" is not defined – user918204 Oct 16 '19 at 12:53
  • @user918204 did you also import `withNamespaces` ? – octobus Oct 16 '19 at 12:56
  • I already imported withN. Do i need to import withNamsepaces as well? – user918204 Oct 16 '19 at 12:59
  • @ElAoutarHamza You are right sir. I misunderstood the question. Updated my answer. – octobus Oct 16 '19 at 13:12
  • @user918204 I updated my answer. What does `withN` mean, I checked the docs there is no export for `withN` – octobus Oct 16 '19 at 13:15
  • My guess, OP wants to import `withNamespaces` and for some reason he's importing `withN`... – Hamza El Aoutar Oct 16 '19 at 13:16
  • @ElAoutarHamza Yeah, that's why thought at first and answered wrongly :) – octobus Oct 16 '19 at 13:18
  • how do i export withNamspace when i already have an export for connect function?. Thats my question – user918204 Oct 16 '19 at 13:20
  • @user918204 Check this https://stackoverflow.com/questions/51265319/using-compose-and-connect-together-in-react-js-redux. You can use it with compose. – octobus Oct 16 '19 at 13:25
  • I implemented compose and now i get "Cannot set property 'props' of undefined" error. Here is my code `const enhance = compose( connect( mapStateToProps,{withNamespaces}, { logOut })(withRouter(Header)));` – user918204 Oct 16 '19 at 13:38
  • I believe it should be `const enhance = compose(withRouter, withNamespaces connect(mapStateToProps, {logOut}));` and then `export default enhance(Header);` – octobus Oct 16 '19 at 14:32
  • @octobus i still get "Cannot set property "props" of undefined – user918204 Oct 17 '19 at 06:14
  • @user918204 On which line you are getting the error? That error should be independant from this one. – octobus Oct 17 '19 at 06:16
  • @octobus kindly check the image attached in the post update – user918204 Oct 17 '19 at 06:44
  • The errır is entirely a different error. I am not sure about the answer. But you have a functional component. `this` keyword is a reference to something different than a class based component. Don't assign props to this.props just used it as `props` only – octobus Oct 18 '19 at 06:24