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
When we render DatePicker inside another component and save the date format for the DatePicker inside its parent component as a state variable, then upon updating the state in parent component that is passed in the DatePicker as props do update the props in DatePicker but do not display the date in new format on the very first update. This is when the state in the parent component has changed via some action other than the DatePicker's.
Expected Behavior
Render DatePicker component.
Keep the dateFormat in the state of its parent component
Change the dateFormat in the parent component state and pass it to DatePicker Component
DatePicker should display the date in the new passed date format.
Current Behavior
Render DatePicker component.
Keep the dateFormat in the state of its parent component
Change the dateFormat in the parent component state and pass it to DatePicker Component
DatePicker still displays the date in the old format until another componentWillReceiveProps is called
Possible Solution
I reviewed the code of the library and found the bug.
When componentWillReceiveProps is invoked it compares the value from newProps with this.getValue() and if they are changed then state is set by creating new date values by calling the function makeDateValues and this function is passed the value from the newProps.
makeDateValues this function then calls makeInputValueString and the bug lies in this function.
In makeInputValueString function the dateFormat being used to format the date is this.props.dateFormat while the dateFormat may have been changed in the latest nextProps.
There are two possible solutions either save dateFormat in the state of DatePicker or pass dateFormat down the above function calls.
Steps to Reproduce (for bugs)
Render DatePicker component.
Keep the dateFormat in the state of its parent component
Change the dateFormat in the parent component state and pass it to DatePicker Component which will invoke DatePicker's componentWillReceiveProps
Your Environment
Version used: github:pushtell/react-bootstrap-date-picker#f622dc8872dd180324ba5d3c295d009848f5814b
Browser Name and version: Any
Operating System and version (desktop or mobile): Any
The text was updated successfully, but these errors were encountered:
When we render DatePicker inside another component and save the date format for the DatePicker inside its parent component as a state variable, then upon updating the state in parent component that is passed in the DatePicker as props do update the props in DatePicker but do not display the date in new format on the very first update. This is when the state in the parent component has changed via some action other than the DatePicker's.
Expected Behavior
Current Behavior
Possible Solution
I reviewed the code of the library and found the bug.
When
componentWillReceiveProps
is invoked it compares thevalue
fromnewProps
withthis.getValue()
and if they are changed thenstate
is set by creating new date values by calling the functionmakeDateValues
and this function is passed the value from thenewProps
.makeDateValues
this function then callsmakeInputValueString
and the bug lies in this function.In
makeInputValueString
function thedateFormat
being used to format the date isthis.props.dateFormat
while thedateFormat
may have been changed in the latestnextProps
.There are two possible solutions either save
dateFormat
in the state of DatePicker or passdateFormat
down the above function calls.Steps to Reproduce (for bugs)
Your Environment
The text was updated successfully, but these errors were encountered: