Я создаю приложение, используя реактивный и избыточный. я создал редуктор с именем LanguageReducer. js для смены языков в моем приложении. ниже его LanguageReducer. js:
import { english } from '../../assets/jsons/english';
import { romanian } from '../../assets/jsons/romanian';
const INITIAL_STATE = romanian;
export default (state = INITIAL_STATE, action) => {
switch(action.type) {
case 'language_data':
return action.payload;
default:
return state;
}
}
их я создал languageaction. js вот так:
export const selectLanguage = (val) => {
return{
type: 'language_data',
payload: val
};
};
в моем реагирующем нативном компоненте я злюсь:
import React, { Component } from "react";
import { Text, View } from "react-native";
import { connect } from "react-redux";
const mapStateToProps = (state, ownProps) => ({
lang: state.lang
});
const mapDispatchToProps = {
// ... normally is an object full of action creators
};
class MyComponent extends Component {
constructor(props){super(props)}
render() {
console.log(this.props.lang)
return ( <Text>{this.props.lang.takeawayScreen.title}</Text>);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);
мой engli sh. js это так:
export const english = {
welcomeScreen: {
loginButton: "Login with email",
loginFacebook: "Login with Facebook",
welcomeText:"Get in love with your favorite food right now with our application!",
continueBy: "Continue with ..."
},
homeScreen: {
diningText: "View Restaurants",
recomandedTitle: "Recommended Restaurants",
recomandedDescription: " Recommended restaurants based on your searches"
},
takeawayScreen: {
title: "Search for Takeaways",
subtitle:" Fill all the required inputs and find restaurants in your location to get your loved food",
destinationPlaceholder: "Search or get your current location",
bookingDatePlaceholder: "Select date",
timePlaceholder: "select hour",
partySizePlaceholder: "number of guests",
guestsword: "guests",
dialogTitle: "Enter number of guests",
dialogInputPlaceholder: "Number of guests",
rangeWord: "Range",
findButton: "FIND RESTAURANTS",
pickerText: "Select the number of guests",
guestsLabel1: "One Guest",
guestsLabel2: "Two Guests",
guestsLabel3: "Three Guests",
guestsLabel4: "Four Guests",
guestsLabel5: "Five Guests"
},
dineinScreen: {
title: "Search for Dine In",
subtitle:" Fill all the required inputs and find restaurants in your location to get your loved food",
destinationPlaceholder: "Search or get your current location",
bookingDatePlaceholder: "Select date",
timePlaceholder: "select hour",
partySizePlaceholder: "number of guests",
guestsword: "guests",
dialogTitle: "Enter number of guests",
dialogInputPlaceholder: "Number of guests",
rangeWord: "Range",
findButton: "FIND RESTAURANTS",
pickerText: "Select the number of guests",
guestsLabel1: "One Guest",
guestsLabel2: "Two Guests",
guestsLabel3: "Three Guests",
guestsLabel4: "Four Guests",
guestsLabel5: "Five Guests"
}
};
в моей консоли это показывает мне это объект, когда я вызываю console.log(this.props.lang)
:
"lang": Object {
"homeScreen": Object {
"diningText": "Vezi restaurante",
"recomandedDescription": "Restaurante recomandate in functie de cautarile tale",
"recomandedTitle": "Restaurante recomandate",
},
"welcomeScreen": Object {
"continueBy": "Continuați prin ...",
"loginButton": "Login cu email",
"loginFacebook": "Login cu Facebook",
"welcomeText": "Indragostiți-vă de mâncarea preferată chiar acum cu aplicația noastră!",
},
},
, когда я запускаю приложение, оно показывает мне эту ошибку: TypeError: TypeError: undefined не является объектом (оценка 'this.props.lang.takeawayScreen.title' ). Я не знаю, почему в консоли он не показывает полный объект языка, что я пропустил?