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

Cannot pass props to modal 'TypeError: Cannot read property of 'showEditModal' of undefined' #213

Open
garethveale opened this issue Apr 14, 2018 · 1 comment

Comments

@garethveale
Copy link

Firstly, I'd like to thank you for this component - it's extremely useful.

I have an issue: I am trying to create touchable list items that, when pressed, show a modal to view and edit information.

However, if I call the onPressEdit function and pass it props as an argument I receive error:
TypeError: Cannot read property of 'showEditModal' of undefined

But I can call onPressEdit without passing arguments and it correctly opens the modal. Am I missing something here please guys? Any help would be greatly appreciated.

At present I have:
Food.js - renders flat list
TrackedItem.js - returns each item in the list
EditModal.js

Food.js

  constructor(props) {
    super(props);
    this.state = {
    };
    this.onPressEdit = this.onPressEdit.bind(this);
  }

onPressEdit = name => {
  this.refs.editModal.showEditModal(name);
}
....
render() {
  return(
      <FlatList
              data={this.state.foods}
              renderItem={({ item }) =>
                <TrackedItem
                  {...item}
                  onPress={this.onPressEdit}
                />
              }
              keyExtractor={(item, index) => index.toString()}
          />
      <EditModal ref={'editModal'} parentFlatList={this} />
  )
}

TrackedItem.js

<ListItem
  title={this.props.name}
  onPress={this.props.onPress(this.props.name)}
/>

EditModal.js

showEditModal = name => {
  this.refs.editModal.open();
  this.setState({ name });
}

<Modal
  ref={'editModal'}
  position='top'
>
@vanqui1994
Copy link

the same question :(

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