Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined is not an object (evaulating '_this.ActionSheet.show') #111

Open
bmwertman opened this issue May 11, 2020 · 2 comments
Open

undefined is not an object (evaulating '_this.ActionSheet.show') #111

bmwertman opened this issue May 11, 2020 · 2 comments

Comments

@bmwertman
Copy link

I've wrapped ActionSheet in a class component, call it MyActionSheet with some standard styling that I plan to use throughout my app.

import React, { Component } from 'react'
import { View, Text } from 'react-native'
import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet'
import Colors from '../assets/Colors.js'

export default class MyActionSheet extends Component {
  constructor (props) {
    super(props)
    this.state = {
      title: props.title,
      options: props.options
    }
  }

  componentDidMount () {
    this.showActionSheet() // I verified this is available w/ a debugger statement just above it
  }

  showActionSheet = () => {
   this.ActionSheet.show()
 }

  render () {
    return (
      <ActionSheet
        useNativeDriver={false}
        styles={{
          titleBox: {
            alignItems: 'flex-start',
            height: 40,
            justifyContent: 'flex-end',
            paddingHorizontal: 10
          }
        }}
        title={
          <View style={{ flexDirection: 'row' }}>
            <View style={{ paddingLeft: 5, justifyContent: 'flex-end' }}>
              <Text style={{
                color: Colors.dkBlue,
                fontWeight: 'bold'
              }}
              >
                {this.state.title}
              </Text>
            </View>
          </View>
        }
        options={this.state.options}
        cancelButtonIndex={0}
        destructiveButtonIndex={this.state.options.length - 1}
        onPress={(index) => { /* do something */ }}
      />
    )
  }
}

I'm then passing MyActionSheet to one of my main view components which passes props down to MyActionSheet as they're received.

export default class MainView extends Component {
  constructor (props) {
    super(props)
    this.state = {
      showActionSheet: props.options ? props.options : false
    }
    render () {
        return (
            <View>
                <Text> My View</View>
                {this.state.showActionSheet
                  ? <BuddyActions show={this.props.options} title={this.props.title} options={this.props.options}/>
                  : null
             </View>
        )
    }
}

My MainView component then renders the MyActionSheet using a ternary condition and I try to call this.ActionSheet.show() in ComponentDidMount but I get the error in the title undefined is not an object (evaulating '_this.ActionSheet.show')

There is probably something fundamental I'm missing but I've been on this all weekend.

@heidji
Copy link

heidji commented Aug 4, 2020

did you find the problem? i'm stuck.

@heidji
Copy link

heidji commented Aug 4, 2020

ah, i am using hooks, had to use ref.current.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants