【问题标题】:React native: how can i pass value in my custom componentReact Native:我如何在我的自定义组件中传递值
【发布时间】:2018-03-14 15:19:27
【问题描述】:

我想在我的自定义组件中传递我的参数值,所以下面是我的代码

Header.js

class Header extends Component {

constructor(props) {
    super(props);
}


render() {
    return (
        <View >
        <Text >Title</Text>
        <Text>subtitle</Text>
        </View>
    );
   }

 }

我从 ma​​in.js

调用我的 Header.js
class Main extends Component {

constructor(props) {
    super(props);
}


render() {
    return (
        <Header title = {this.props.navigation.state.params.screen_title} subtitle= {this.props.navigation.state.params.subtitle} />
    );
    }

 }

我在标题组件中传递了标题和副标题,我只是想知道如何在标题组件中访问传递的变量值?你的所有建议都很有价值

【问题讨论】:

标签: react-native react-navigation


【解决方案1】:

很简单,你可以通过

this.props.title
this.props.subTitle
this.props.nameOfTheProps

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多