Guest User

Untitled

a guest
Oct 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import './App.css';
  3. import { connect } from 'react-redux';
  4. import Main from './Main/Main.js';
  5. import FooterPage from './Footer/Footer.js';
  6. import { I18nProvider } from '@lingui/react'
  7.  
  8. class App extends Component {
  9.  
  10.  
  11. state = {
  12. catalogs: {},
  13. }
  14.  
  15. loadCatalog = async (language) => {
  16. const catalog = await import(
  17. './locales/'+language+'/messages.json')
  18.  
  19. this.setState(state => ({
  20. catalogs: {
  21. ...state.catalogs,
  22. [language]: catalog
  23. }
  24. }))
  25. }
  26.  
  27. componentDidMount() {
  28. this.loadCatalog(this.props.language)
  29. }
  30.  
  31. shouldComponentUpdate(nextProps, nextState) {
  32. const { language } = nextProps
  33. const { catalogs } = nextState
  34.  
  35. if (language !== this.props.language && !catalogs[language]) {
  36. this.loadCatalog(language)
  37. return false
  38. }
  39.  
  40. return true
  41. }
  42.  
  43. render() {
  44. /// console.log('props',this.props);
  45. const {loggingIn, user, userType} = this.props;
  46. const { language } = this.props
  47. const { catalogs } = this.state
  48. //if (!catalogs[language]) return
  49. return (
  50. <I18nProvider language={language} catalogs={catalogs} >
  51. <div className="">
  52.  
  53. <Main />
  54. <FooterPage />
  55. </div>
  56. </I18nProvider>
  57.  
  58. );
  59. }
  60. }
  61.  
  62. function mapStateToProps(state) {
  63. const { loggingIn, user, userType} = state.authentication;
  64. console.log(state);
  65. const { language } = state.locale
  66. return {
  67. loggingIn,
  68. user,
  69. userType,
  70. language,
  71. };
  72. }
  73. export default connect(
  74. mapStateToProps,
  75. )(App)
Add Comment
Please, Sign In to add comment