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

ERROR TypeError: Cannot read property 'setState' of undefined, js engine: hermes #156

Open
getsettalk opened this issue Sep 24, 2023 · 4 comments

Comments

@getsettalk
Copy link

Hi when i going to watch our device oriantion than showing this error :

ERROR TypeError: Cannot read property 'setState' of undefined, js engine: hermes

Here is code 🤞 :

   useEffect(() => {
    lor(); // Start listening for orientation changes
    
    return () => {
      rol(); // Stop listening when the component unmounts
    };
  }, []); 

this is screenshots:

image
image

please fix as soon as possiable

@mohamedatef98
Copy link

Hello @getsettalk
I am not working on the library, I just want to help

If you check the code for the "listenOrientationChange" function, you will see that it's designed to be only used with a class based components and it relays on the value of "this" to be passed as an argument to call setState to update the component when the orientation changes

Check the provided example here https://github.com/marudy/react-native-responsive-screen/tree/master/examples/responsive-screen-orientation-change

My suggestion to solve the issue, is that you use the new hook introduced by react native "useWindowDimensions", you can just call it inside your functional component and ignore the return (since the width and height are handled by this library), and it should automatically render your component when orientation changes, and will also do the required cleanup on unmounting
Also keep in mind that you will need to move your styles inside the component function so that the "hp" and "wp" are re-calculated when orientation changes.

Hope that helps

@getsettalk
Copy link
Author

getsettalk commented Oct 18, 2023 via email

@mohamedatef98
Copy link

@getsettalk
As i said, I am not a developer for this library, I just wanted to provide a solution for your question

I would be happy to submit a PR to update this library, but It seems no one is maintaining it and the PR won't be submitted.

@getsettalk
Copy link
Author

getsettalk commented Oct 19, 2023 via email

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