Passing props to child components with a React Navigation

风流意气都作罢 提交于 2021-01-29 05:35:13

问题


I'm trying to figure out how to pass props to the 'Camera' component but getting a syntax error when i try

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

cant seem to find documentation to help on this one. Im sure its simple if you know how - hoping someone can assist.

my code

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:


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

check this



来源:https://stackoverflow.com/questions/60664242/passing-props-to-child-components-with-a-react-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!