You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the component is being used in "controlled" mode, it should use the state passed via "selected" prop. In the example above, the selected state is purposely not updated. It was expected that the calendar would not work, since the selected values aren't being updated.
I was trying to implement a behavior where if the range is already selected, and the user click on a new day, the range is reset:
Since the internal state is updated via useEffect, it causes a small flicker. The sequence of events is:
User click -> internal range state updated -> onSelect callback -> external state updated (range reset) -> internal state is updated via useEffect due external state change.
thanks @matheusmb for your detailed report ! you are right the controlled vs uncontrolled state isn't the ideal here.
The code should read something like:
consthandleSelect=(value: string)=>{if(onSelect){onSelect(value);// If the component is controlled, trigger the onSelect callback}else{setInternalSelected(value);// If the component is uncontrolled, update the internal state}};
Code
Expected Behavior
Since the component is being used in "controlled" mode, it should use the state passed via "selected" prop. In the example above, the selected state is purposely not updated. It was expected that the calendar would not work, since the selected values aren't being updated.
I was trying to implement a behavior where if the range is already selected, and the user click on a new day, the range is reset:
Since the internal state is updated via useEffect, it causes a small flicker. The sequence of events is:
User click -> internal range state updated -> onSelect callback -> external state updated (range reset) -> internal state is updated via useEffect due external state change.
Actual Behavior
The calendar has its own internal state. The external state is updated via useEffect.
CodeSandbox
Video
Tab-App.tsx.nodebox.CodeSandbox.mp4
PS: I throttled the CPU in 6x to make it more noticeable
The text was updated successfully, but these errors were encountered: