Skip to content
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

DatePicker Caches onChange #3042

Closed
2 tasks done
PatrickDuncan opened this issue Jun 12, 2019 · 0 comments · Fixed by #3050
Closed
2 tasks done

DatePicker Caches onChange #3042

PatrickDuncan opened this issue Jun 12, 2019 · 0 comments · Fixed by #3050

Comments

@PatrickDuncan
Copy link

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 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.

Chrome v74.0.3729.169

carbon-components: v10.3.0
carbon-components-react: v7.3.0

Steps to reproduce the issue

  1. Use React Hooks to have a simple state that has 2 dates
    const [dates, setDates] = useState({date1: '', date2: ''})
  2. Control the DatePickers with that state
  3. When you use setDates you will need to use dates to ensure that changing 1 date doesn't clear the state of the other
  4. You will notice that when you print the dates variable in your onChange function it will always be equal to the initial state {date1: '', date2: ''}
  5. Meaning that the DatePicker is not re-rendering properly.

Sandbox

https://codesandbox.io/s/codesandbox-1r9ku

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant