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: this_currentMessageBarAlert.hideMessageBarAlert #24

Closed
ikendoit opened this issue Dec 29, 2017 · 9 comments
Closed

undefined: this_currentMessageBarAlert.hideMessageBarAlert #24

ikendoit opened this issue Dec 29, 2017 · 9 comments

Comments

@ikendoit
Copy link

ikendoit commented Dec 29, 2017

Hello, I was trying out the message bar and i get this error :

screenshot_1514530068

my testMess():

66.  testMess(){
  67.	MessageBarManager.showAlert({
		title: "title jere", 
		message: "a message for a message", 
		alertType: "success",
	});
	console.log("did a message show ??? ");
  }

My ComponentDidMount:

  componentDidMount() {
    this.setState({
      ..........
    });
    MessageBarManager.registerMessageBar(this.refs.alert);
    this.testMess();
  }

I set up everything as told in the manual but this didn't work.
Has anyone had this problem before ? i tried playing around with the MessageBarManager.js but nothing worked.

@hamidfzm
Copy link

I have the same problem. I think alert reference register has problem.

@Talor-A
Copy link
Owner

Talor-A commented Jan 12, 2018

are you sure that this.refs.alert is != undefined? that's the only way I can see this error happening.

@hamidfzm
Copy link

I think it is a binding problem. I used https://github.com/Qlean/react-native-messages. It's a simple message bar (So simple compared to this project) but they implemented a better code( or binding solution) for message bar manager. Please take a look at their source code.

@ugendrang
Copy link

+1

@Talor-A
Copy link
Owner

Talor-A commented Jan 17, 2018

@hamidfzm thanks for showing me that library, it's definitely a better solution. I unfortunately don't have the time to do any major refactoring of this library right now, but I'll look into this issue again. unfortunately so far I haven't been able to reproduce the problem, but if anyone wants to share a simple demo project I'll take a look.

@blntylmn
Copy link

Anyone has issue with this problem. You can surround the registerMessageBar function in a setTimeout function like below :

componentDidMount() {
    setTimeout(() => {
      MessageBarManager.registerMessageBar(this.alert);
    }, 0);
  }

and don't use ref as string

<MessageBarAlert  ref={(a) => { this.alert = a; }} />

@ikendoit don't use setState in your componentDidMount. If you really need it in componentDidMount; surround it with setTimeout 👍

@ikendoit
Copy link
Author

Thank you @blntylmn , the way you used setTimeout was very clever ! I will surely try it your way.

@xxzefgh
Copy link

xxzefgh commented Jul 29, 2018

You can just register in ref callback:

<MessageBar
  ref={ref => {
    MessageBarManager.registerMessageBar(ref);
  }}
/>

@phillbaker
Copy link

This seems similar to the upstream issue: KBLNY#46

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

7 participants