I want to pass one string value from native android Main Activity class to react native component. I apply this code, but once I print the "data" in the log it shows undefined. I am not able to understand what is the problem. I am a beginner in react native. Thanks in advance.
In Main Activity:
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected Bundle getLaunchOptions() {
Bundle initialProperties = new Bundle();
initialProperties.putString("var_1","Im the first var");
return initialProperties;
}
};
}
In App.js:
export default class App extends Component<Props> {
render() {
var data = this.props.var_1;
console.log(data);
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.welcome}>{this.props.var_1}</Text>
</View>
);
}
}