primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Calendar: InputBox does not re-render when value is programmatically set

Open Achill113 opened this issue 3 years ago • 1 comments

Describe the bug

I am using onShow to set the value for the Calendar to new Date(). This does not re-render the InputBox to display the newly set value.

Reproducer

https://codesandbox.io/s/primereact-calendar-defect-bf03sb

PrimeReact version

8.5.0

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

  1. set onShow to set value to anything (I'm setting to new Date())
  2. set showIcon to true
  3. Click icon
  4. InputBox does not change

Expected behavior

InputBox should reflect the current value of the Calendar component even when set programmatically.

Achill113 avatar Sep 13 '22 19:09 Achill113

Tricky one related to state and re-renders

melloware avatar Sep 13 '22 19:09 melloware

Hi @Achill113 , Could you try the same case using onChange unless you have a specific reason to use onShow?

You can see an example I made by forking your example from the link below; https://codesandbox.io/s/primereact-calendar-defect-forked-knnpzi?file=/src/demo/CalendarDemo.tsx

ulasturann avatar Oct 11 '22 11:10 ulasturann