last day (14 days later) » 

12:16 PM
0
Q: pass props to DrawerContent component

pythonBeginnerI want to pass props to Drawer so that i can display the name of user in the drawer component. If i export DrawerContent, i dont get the props like navigation etc. routes.js const navitems =[ { name:'Home', nav:'classesnew', }, { name:'Device', nav:'start', ...

 
Try using const ContentDrawer = connect(mapStateToProps, mapDispatchToProps)(DrawerContent) and then use ContentDrawer instead of DrawerContent in the Drawer component
 
Do you mean to say export const Drawer = DrawerNavigator(DrawerRoutes ,{ contentComponent:({navigation})=> <ContentDrawer navigation={navigation} routes={DrawerRoutes} />, }); const ContentDrawer = connect(mapStateToProps, mapDispatchToProps)(DrawerContent); ?
 
Yes, thats what I wanted you to test
 
What about the class DrawerContent extends React.Component? I did not understand between DrawerContent and ContentDrawer component.
 
See the component name will be the same, we are using connect on it and it returns a separate component which is connected to redux states which we rename as ContentDrawer and use it in our application. Let me know if it works
 
12:16 PM
@ShubhamKhatri I have updated my code. My DrawerContent is not rendering this way.
I am sharing my full code with you. Its a routes.js file import React from 'react';
import { StackNavigator, DrawerNavigator, TabNavigator } from 'react-navigation';
import { View, Text, Image, TouchableOpacity, StyleSheet } from 'react-native';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import Icon from 'react-native-vector-icons/Ionicons';

import { selectUser } from './App/selectors';
import { loadInitialData } from './App/actions';
import App from './App';
its a index file import {Drawer} from './routes';

const initialState = {};
const store = configureStore(initialState);

const App = () => (
<Provider store={store}>
<Drawer />
</Provider>
);

export default App;
 
Hi am leaving for home now, will ping you once I reach
 
12:53 PM
sure. Thanks for your consideration :). Out question, are you Indian?
 
1:36 PM
yes
are u der?
 
yes I am here
 
ok
So any error that you get
 
I dont get DrawerComponent render so componentDidMount is not working
Doing above way
 
What happens when you do as you had done before
 
1:54 PM
The drawer is shown but i get error like uncaught at appSaga
at takeLatestHelper
at initialize
at loadInitialData
at _callee
_callee$@http://192.168.1.139:19001/./
Also the console.log which i have done in componentDidMount and render function in DrawerContent is not shown
class DrawerContent extends React.Component{
constructor(props) {
super(props)
}

componentDidMount() {
console.log('props are', this.props); // not showing this in console
this.props.loadInitialData();
}
 
Let me check
I don't know whether that makes a difference but can you try to add the DrawerContent in a separate file export it from there like

export default connect(mapStateToProps, mapDispatchToProps)(DrawerContent);
and then import in the Drawer file like

import DrawerContent from 'path/to/file'
and use as you were doing
Also define the mapStateToProps and mapDispatchToProps function there
 
2:18 PM
Also define the mapStateToProps function there? Do you mean to say in routes.js too? Just the function
 
2:44 PM
I meant, mapStateToProps , mapDispatchToProps, DrawerContent and connect must be in the same file
 

last day (14 days later) »