React-Native - 将数据/函数传递给组件

时间:2016-11-15 11:32:47

标签: react-native components parent-child

我在父组件中有这个功能:

toggle   = () => {
    console.log('123');
}

这是父组件,我希望在我的一个子组件(层次结构中的第3个)中传递此函数(或者能够实际使用此函数)。

我会尝试描述它:

<ScrollView
    showsVerticalScrollIndicator={false}
>
    <Category title={'news'} />
    <Category title={'entertainment'} toggleDropZone={this.toggleDropZone} />
</ScrollView>

Category组件导出项目列表:

<Item title="1" />
<item title="2" />

所以,我想从我的Item组件中使用切换功能。我知道使用道具toggle={this.toggle}的方法,但我不想在每个孩子中传递它,因为它不实用。

还有其他选项可以将这些数据传递给我的子组件,或者从我的子组件访问主要父组件的其他方式吗?

非常感谢。

0 个答案:

没有答案
相关问题