-
Notifications
You must be signed in to change notification settings - Fork 582
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
Component doesn't rerender if realm object used as state. #2730
Comments
This is most likely a duplicate of #2655 |
@TuTejsy did you manage to resolve your issue? Also facing this problem. |
This is my solution to refresh the data and rerender the UI.
|
@TuTejsy sorry for the long wait here and thanks for the detailed reproduction. There's two of things going on here, the main issue is in the https://github.com/TuTejsy/Test-Environment/blob/master/src/containers/hooks/useCount.js#L10-L31 file:
I would advice using a property from the object, as the state in function useCount() {
const [count, setCount] = useState();
useEffect(() => {
const countObj = DB.object(id);
const listener = () => {
setCount(countObj.count);
};
countObj.addListener(listener);
return () => {
countObj.removeListener(listener);
};
}, []);
return count;
} Closing this for now, please re-open if this suggestion produce unexpected results. |
Goals
I use setState hook with realm object and expect that Component will re-render after realm object modified
Expected Results
Component should re-render
Actual Results
Component re-render in DEBUG mode, but it doesn't in RELEASE mode
Steps to Reproduce
I have created Test Environment where you can easily reproduce it: https://github.com/TuTejsy/Test-Environment
Demo in DEBUG mode: https://youtu.be/LZxPk5P5TK4
Demo in RELEASE mode: https://youtu.be/HX617LHOO3Y
Code Sample
I have created Test Environment where you can easily reproduce it: https://github.com/TuTejsy/Test-Environment
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: