S S
S S

Reputation: 1503

Store in a variable in react native

I am trying to set I18n.t to a variable then call this variable inside my class. But I am getting TypeError: undefined is not an object.

import I18n from 'react-native-i18n';
let tt = I18n.t;

class App extends Component {
  render(){
    return (
      <View>
         <Text>{tt('greeting')}</Text>
      </View>
    )
  }
}

Upvotes: 0

Views: 485

Answers (1)

krsna
krsna

Reputation: 171

This will be useful check it out:

var tt = (translation) => I18n.t(translation);


<Text>{tt('greeting')}</Text>

Upvotes: 2

Related Questions