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

post-robot in React - cannot read properties of undefined (send) #115

Open
lcpages opened this issue Feb 3, 2023 · 2 comments
Open

post-robot in React - cannot read properties of undefined (send) #115

lcpages opened this issue Feb 3, 2023 · 2 comments

Comments

@lcpages
Copy link

lcpages commented Feb 3, 2023

I have install the post-robot package to my react project.

My project works as a web app which is embedded into a Web Client application and displayed within an IFrame. I know this web client uses post-robot library to handle communication events and I also know it is has an EventListening set on "loading".

Like any other packages, I have imported post robot in my main app component

import { postRobot } from 'post-robot'

I tried to send the corresponding message the webclient is expecting :

const sendMessage = (message, success) => {
    //parent window is the holding web client, message is "loading", success is false
    postRobot.send(window.parent, message, success)

however, when this function is called in the hook at runtime, an error occurs saying that React does not recognize '.send()' as a valid method.

error1

I am puzzled. React seems to not recognize post-robot package, however, VS does not preventively throw any warning/errors (like it usually does) which would mean the package has been installed successfully. Am I doing this wrong or is post-robot not meant to be used on a React project ?

@zackspear
Copy link

You need to use the default export

import postRobot from 'post-robot'; // will work

Not a named export

import { postRobot } from 'post-robot'; // won't work

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

@lcpages
Copy link
Author

lcpages commented Mar 19, 2023

@zackspear , thank you for the answer. It works.

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