我想从本地android Main Activity类传递一个字符串值来响应本地组件。我应用了此代码,但是一旦我在日志中打印“数据”,它就会显示未定义。我无法理解问题所在。我是React Native的初学者。提前致谢。
在主要活动中:
@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;
}
};
}
Run Code Online (Sandbox Code Playgroud)
在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>
);
}
}
Run Code Online (Sandbox Code Playgroud)