heba
heba

Reputation: 119

Adding react-native side menu to my application (from react-native elements) - application crashes on launching

I have been trying to implement this side menu in my android application (in react native). I tried modifying it by putting it in a class and adding semicolons, but the app crashes every time I launch it.

here is my full code:

ps: my editor (visual studio code) points out an error at line 24(onSideMenuChange (isOpen: boolean) {) but I'm not sure whats is wrong with this line.

    import { SideMenu, List, ListItem } from 'react-native-elements';
    import {
      AppRegistry,
      StyleSheet,
      Text,
      View
    } from 'react-native';

    export default class myApp extends Component {
      constructor () {
      super();
      this.state = {
        isOpen: false
      };
      this.toggleSideMenu = this.toggleSideMenu.bind(this);
        }

        onSideMenuChange (isOpen: boolean) //error: [js] 'types' can only be used in a .ts file.            
        {
          this.setState({
            isOpen: isOpen
          });
        };

        toggleSideMenu () {
          this.setState({
            isOpen: !this.state.isOpen
          });
        };

        render () {
          const MenuComponent = (
            <View style={{flex: 1, backgroundColor: '#ededed', paddingTop: 50}}>
              <List containerStyle={{marginBottom: 20}}>
              {
                list.map((l, i) => (
                  <ListItem
                    roundAvatar
                    onPress={() => console.log('Pressed')}
                    avatar={l.avatar_url}
                    key={i}
                    title={l.name}
                    subtitle={l.subtitle}
                  />
                ))
              }
              </List>
            </View>
          )

          return (
            <SideMenu
              isOpen={this.state.isOpen}
              onChange={this.onSideMenuChange.bind(this)}
              menu={MenuComponent}>
              <App toggleSideMenu={this.toggleSideMenu.bind(this)} />
            </SideMenu>
          );
        }
        }


     AppRegistry.registerComponent('myApp', () => myApp);

Upvotes: 0

Views: 1097

Answers (1)

kumar
kumar

Reputation: 109

onSideMenuChange (isOpen: boolean) //error: [js] 'types' can only be used in a .ts file.            
        {
          this.setState({
            isOpen: isOpen
          });
        };

here colon in not required, remove colon from line onSideMenuChange (isOpen) adn it will work

Upvotes: 1

Related Questions