is onPress memoized?
ansh opened this issue · 17 comments
Is the onPress prop memoized? Because if it is, there is an issue since I am using state in onPress and it using the wrong state.
Using Expo SDK 46
It seems like onPressIn
works because it is directly being passed into the component, but ideally I would like to use onPress
as it is significantly better UX.
Here is a reproducible demo: https://snack.expo.dev/@anshnanda/awesomebutton-not-working
Same issue.
I have reached a solution via the help of StackOverflow: https://stackoverflow.com/questions/74297972/react-native-really-awesome-button-onpress-does-not-update-function-when-state-c
However, it is clear that this bug needs to be addressed in the repository.
Can confirm this bug exists and needs to be fixed. It seems to not be present in the release version
@eeshankeni It is present in the release version. Check out my demo: https://snack.expo.dev/@anshnanda/awesomebutton-not-working
Weird, I tried to toggle the button's colour between two options using a state. It worked fine in the release but not in the latest version.
Can you provide a demo on Snack or a repo/gist? @eeshankeni
@septpointdeux This is effectively the solution I hinted at in my SO answer. Did you apply the fix in a local clone of the repo or are you planning to issue a pull request with the fix applied?
@awreese Thx i effectively followed your advises on SO 👍. The PR is done.
It has been almost a month, with a perfectly good PR created, and the maintainer of this package has not even responded. I have emailed him and he has seen the email many times and yet is probably too busy to maintain this.
So, I have forked the package, cleaned up the code, updated the dependencies, and published it under react-native-raised-button
on NPM.
Please find it here https://www.npmjs.com/package/react-native-raised-button?activeTab=readme
and here https://github.com/ansh/react-native-raised-button
Looking forward to your contributions @septpointdeux and @awreese
Hey @ansh
Thanks for your fork, I've noticed that it too has a the same onPress bug as before and the color of the button does not change with every onPress. Would have made an issue on your repo directly but there seems to be no option.
Do check out my expo snack https://snack.expo.dev/@esean_keni/8465d3
Notice how the button changes colour only after multiple attempts. When it should instead be changing with every press.
Thank you!
@eeshankeni The example snack I initially gave that did not work with this package works now: https://snack.expo.dev/@anshnanda/awesomebutton-not-working so my fork solved my issue.
Not sure why your example doesn't work. Let me take a look.
@eeshankeni I have debugged your Snack and it seems like there is another bug in the original react-native-really-awesome-button package! This is actually absurd. I regret using this package now.
But in any case, the simplest fix is not pressing the button back-to-back. If you wait 1-2 seconds between pressing the button, the color changes every time. However, if you press the button in rapid succession, the color doesn't change and it doesn't register the new state. Not sure why this happening (maybe @awreese and @septpointdeux can take another look).
@ansh damn this package seems more trouble than its worth. Which is unfortunate cause its really rather good
is the dev dead?
However, since the original dev is not active, I made a fork that works better and will be maintained:
https://github.com/ansh/react-native-raised-button
All done in accordance with the MIT license