Possible Unhandled Promise Rejection undefined is not a function

Viewed 18511

I am using React Native. I have already check out What is an unhandled promise rejection?, but I can't understand it at all.

When I create a component:

render(){
    const MenuComponent = (
      <MenuScreen CloseSlideMenu={this.SlideMenu.CloseSlideMenu} />
    )
    ...
}

I get the following error:

'Possible Unhandled Promise Rejection (id: 0) TypeError: undefined is not a function (evaluating '_this.OpenSlideMenu.bind(true).then(function() {}))'

this.OpenSlideMenu() is declared in the constructor().

constructor (props, context) {
  super(props, context)

  this.OpenSlideMenu = this.OpenSlideMenu.bind(true).catch(function(e){
    console.log("Promise Rejected");
  });
  this.CloseSlideMenu = this.CloseSlideMenu.bind(true).catch(function(e){
    console.log("Promise Rejected");
  });
}

this.drawer is declared in the render() method:

render () {
  const MenuComponent = (
    <MenuScreen CloseSlideMenu={this.SlideMenu.CloseSlideMenu} />
  )

  return (
    <Drawer
      ref={(ref) => this.drawer = ref}
      content={MenuComponent}
      tapToClose={true}
      openDrawerOffset={170}
      stles={drawerStyles}
      panCloseMask={0.2}
      closedDrawerOffset={-3}
      styles={drawerStyles}
      tweenHandler={(ratio) => ({
        main: { opacity: (2-ratio)/2 }
      })}>
      <GroceryScreen selectedCategory='Todos' OpenSlideMenu={this.OpenSlideMenu} />
    </Drawer>
  )
}

Could someone explain to me why I have this error? How do I fix this?

2 Answers

I was getting a similar error for a different reason: importing an aync function "myFunc" from a Context file using useContext

My error: Unhandled Promiose Rejection is not a function is an instance of a promise

const {
    state: { some, stuff }, myFunc,
} = useContext(SomeContext);

when calling myFunc which took no params/variables do not include parentheses. Changing const output = await myFunc(); to const output = await myFunc; fixed it for me.

Related