-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
ContextProvider - wrap callbacks #1942
Conversation
} | ||
}; | ||
}, [currentDate, onDateChanged, onMonthChange]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main issue we'll have here, is the fact that currentData
will change too often and will re-create the _setDate
callback.
This is btw and known React issue, and they have plans to release a new hook called useEvent
You can read about it here
Anyway, for now I will approve the PR.
We can maybe think of a way to avoid re-creation of the callback for now, maybe keep the currentDate
as a ref value as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm familiar with useEvent
. I removed the prevDate
from the state, as there is no need for that, but I don't see an option removing the currentDate
from the state as the UI needs to react to its changes (today button, selected date, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh definitely, I actually meant to keep it both in state and in ref.
The ref is only meant for the setDate
callback do you won't need to recreate it each time...
It's far from ideal but it can be a temp solution till we'll have something like useEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. Got it.
… callback on every state change
No description provided.