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
Hey guys, I'm using Carbon with React. I'm using the DatePicker component and the onChange function is cached. I was accessing a state var outside of the onChange function (Hooks) and it was always set to the initial value. Other Carbon components had the updated state. Randomizing the key prop fixed the issue because it React re-renders components with a different key.
What package(s) are you using?
carbon-components
carbon-components-react
Detailed description
Hey guys, I'm using Carbon with React. I'm using the
DatePicker
component and theonChange
function is cached. I was accessing a state var outside of theonChange
function (Hooks) and it was always set to the initial value. Other Carbon components had the updated state. Randomizing thekey
prop fixed the issue because it React re-renders components with a different key.Chrome v74.0.3729.169
carbon-components: v10.3.0
carbon-components-react: v7.3.0
Steps to reproduce the issue
const [dates, setDates] = useState({date1: '', date2: ''})
setDates
you will need to use dates to ensure that changing 1 date doesn't clear the state of the otherdates
variable in your onChange function it will always be equal to the initial state{date1: '', date2: ''}
DatePicker
is not re-rendering properly.Sandbox
https://codesandbox.io/s/codesandbox-1r9ku
The text was updated successfully, but these errors were encountered: