sapcc / juno

Monorepo for the Juno microfrontend framework, microfrontend apps, design system and component library
Apache License 2.0
5 stars 3 forks source link

[UI-Components] Endless loop in DateTimePicker when using objects. #575

Closed TilmanHaupt closed 2 months ago

TilmanHaupt commented 2 months ago

Hi! I found a endless loop, which can be created if a controlled DateTimePicker component sets a object instead of a string. I have a "good" and a "evil" example which you can copy into the playground,p:~Htesting)))

πŸ˜‡

import React, { useEffect, useState } from "react"
import { DateTimePicker } from "juno-ui-components"

export default function App() {

const [testState, setTestState] = useState({
    date: {
      end: null
    },
  }) 

  return (
  <DateTimePicker
              value={testState?.date?.end}
              dateFormat="Y-m-d H:i"
              label="Select a end date"
              enableTime
              time_24hr
              required
              onChange={(e, f) => {
                console.log("end date as a string:", f)
                setTestState({ ...testState, date: { end: f } })
              }}
            />
  )
}

😈

import React, { useEffect, useState } from "react"
import { DateTimePicker } from "juno-ui-components"

export default function App() {

const [testState, setTestState] = useState({
    date: {
      end: null
    },
  }) 

  return (
  <DateTimePicker
              value={testState?.date?.end}
              dateFormat="Y-m-d H:i"
              label="Select a end date"
              enableTime
              time_24hr
              required
              onChange={(e, f) => {
                console.log("end date as a object", e)
                setTestState({ ...testState, date: { end: e } })
              }}
            />
  )
}
franzheidl commented 2 months ago

Hey Tilman, thanks for reporting this issue, I can reproduce it locally, too. I think I know where to look, but I will not have the time to investigate any further until mid next week.