使用React导航将道具传递给子组件

时间:2020-03-13 02:49:29

标签: react-native react-props

我试图弄清楚如何将道具传递给“相机”组件,但尝试时会出现语法错误

component= { Camera doSomething={this.doSomething}}  

似乎无法找到有关此文档的文档。如果您知道如何,我肯定很简单-希望有人可以提供帮助。

我的代码

import React, { Component } from 'react';
import Camera from './camera'
import VideoComponent from './video'
import AudioComponent from './audio'
import File from './file'
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { MaterialCommunityIcons } from 'react-native-vector-icons';


const CaptureNav = createMaterialBottomTabNavigator();


class Capture extends Component {
  render(){
    return (
      <CaptureNav.Navigator >

        <CaptureNav.Screen 
          name="Camera" 
          component= {Camera}
          options={{
            tabBarIcon : () => (
              <MaterialCommunityIcons name='camera' color={'black'} size={26} />
            )
          }}
        />

        <CaptureNav.Screen 
          name="Video" 
          component= {VideoComponent} 

        />

        <CaptureNav.Screen 
          name="Audio" 
          component= {AudioComponent}

        />

         <CaptureNav.Screen 
          name="File" 
          component= {File} 

        />

      </CaptureNav.Navigator>
    )
  }
}

export default Capture

1 个答案:

答案 0 :(得分:0)

<Stack.Screen name="Home">
  {props => <HomeScreen {...props} extraData={someData} />}
</Stack.Screen>

check this