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

Multiple instances of Alan is opening while running #35

Closed
Roshan-Thomas opened this issue Aug 16, 2020 · 2 comments
Closed

Multiple instances of Alan is opening while running #35

Roshan-Thomas opened this issue Aug 16, 2020 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@Roshan-Thomas
Copy link

I am building a news application, where alan gives the latest news using the newsapi.

While I am running the application, after it retrives and displays the news, it immeditely opens multiple instances of itself. So when I say read the news, all the instances start reading the news.

  • I used React to build the application
  • Version of alan-sdk-web: 1.3.0

Check out the app here: https://amazing-aryabhata-2fd271.netlify.app/
My repo for the project: https://github.com/Roshan-Thomas/VoiceControlledNewsReaderApp


I initially thought it was an error because I was running it locally, but the same thing happened even when I launched it on netlify.

@andreyryabov andreyryabov added the help wanted Extra attention is needed label Aug 16, 2020
@annmirosh
Copy link
Contributor

Hi, @Roshan-Thomas,

as I can see from your repo, you have already fixed the issue.
Anyway, for people who might have the same issue in the future, here is a code that shows how the Alan Button should be added to the React functional component:

  useEffect(() => {
    alanBtn({
      key: 'alan-project-key',
      onCommand: ({ command, articles, number }) => {
       // Call the client code that will react to the received command
      }
    });
  }, []);

You need to pass an empty array as a second argument to the useEffect hook.
This tells React that your effect doesn’t depend on any values from props or state, so it never needs to re-run. In this case, useEffect hook behaves closer to the componentDidMount method, as a result, only one instance of the Alan Button is created.

@Roshan-Thomas
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants