Created
October 19, 2018 16:37
-
-
Save NgesBrian/9f1d165d536e00030e226f96e0b1a744 to your computer and use it in GitHub Desktop.
error message is this.props.language is undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import './App.css'; | |
import { connect } from 'react-redux'; | |
import Main from './Main/Main.js'; | |
import FooterPage from './Footer/Footer.js'; | |
import { I18nProvider } from '@lingui/react' | |
class App extends Component { | |
state = { | |
catalogs: {}, | |
} | |
loadCatalog = async (language) => { | |
const catalog = await import( | |
'./locales/'+language+'/messages.json') | |
this.setState(state => ({ | |
catalogs: { | |
...state.catalogs, | |
[language]: catalog | |
} | |
})) | |
} | |
componentDidMount() { | |
this.loadCatalog(this.props.language) | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
const { language } = nextProps | |
const { catalogs } = nextState | |
if (language !== this.props.language && !catalogs[language]) { | |
this.loadCatalog(language) | |
return false | |
} | |
return true | |
} | |
render() { | |
/// console.log('props',this.props); | |
const {loggingIn, user, userType} = this.props; | |
const { language } = this.props.language | |
const { catalogs } = this.state | |
//if (!catalogs[language]) return | |
return ( | |
<I18nProvider language={language} catalogs={catalogs} > | |
<div className=""> | |
<Main /> | |
<FooterPage /> | |
</div> | |
</I18nProvider> | |
); | |
} | |
} | |
function mapStateToProps(state) { | |
const { loggingIn, user, userType} = state.authentication; | |
console.log(state); | |
const { language }= state =>state.locale.language | |
return { | |
loggingIn, | |
user, | |
userType, | |
language, | |
}; | |
} | |
export default connect( | |
mapStateToProps, | |
)(App) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment