繁体   English   中英

如何在 React Native 中动态调用模块

[英]How to dynamically call a module in React Native

我想动态添加一个反应原生视图。 这将在调用之前完全不确定。

import React, {Component} from 'react';
import {View} from 'react-native';

export default class HelloWorld extends Component {
    render() {
        return (
            <View>{ /** add a component a view depending on paremeters passed into class in Props**/}</View>
        );
    }
}  

由于这将完全不确定,我不确定如何在不先导入的情况下从另一个模块调用模块。

我该怎么办?

谢谢大家。

如何在 React Native 中动态调用模块

import React, {Component} from 'react';
import {View} from 'react-native';

export default class HelloWorld extends Component {
    render() {
      let dynamicComponent = this.props.displayDynamicComponent ?  <DynamicComponent /> : null;
        return (
            <View>{dynamicComponent}</View>
        );
    }
}  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM