design-system: DateTimePicker React error maximum depth when setting the value state
Bug report
Required System information
- Node.js version: 16.19.0
- NPM version: 8.19.3
- Strapi version: 4.5.6
- Database: Mysql
- Operating system: Windows 11
Describe the bug
The DateTimePicker creates a React error Warning: Maximum update depth exceeded when trying to set the value from a state.
Steps to reproduce the behavior
Use the DateTimePicker from '@strapi/design-system' and set the value via another component
Expected behavior
I would expect to be able to set the value of the component.
Code snippets
import React, { useState } from "react";
import { DateTimePicker, Button, Box } from "@strapi/design-system";
const Component = () => {
const [date, setDate] = useState<Date | null>(null);
return (
<Box>
<Button type="button" aria-label="Reset" onClick={() => setDate(new Date())}>
Click me
</Button>
<DateTimePicker
ariaLabel="Label"
label="Label"
name="date"
onChange={(e: Date) => setDate(e)}
size="S"
value={date}
/>
</Box>
);
};
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 19 (7 by maintainers)
Hi everyone, thank you for your patience I appreciate this is frustrating.
I’ve begun working on this today. It’ll either be released in
1.6.5or1.6.6. From there I can give you a better idea of what version of the strapi admin panel it’ll be fixed in.Hello everybody! Good news! Strapi has just released v4.9.0 and includes Design System v1.6.6 😃
@eucciferri, you have a few choices:
@strapi/design-systemdependencies to1.6.64.8.3which should be released on the 29th March afaik.Nope, there’s a PR we’re working on that solves the issue however 😃
Hello guys! Does anyone know if this issue was solved? Thanks!!
This small change resolved the issue. Removed the value !== dateValue check as well as dateValue from dependency array. I managed to replicate the issue in story book by changing the story - so this really works.
Can someone check this to confirm the fix and prepare a PR? Seems that some people are waiting for this fix - and we are stuck on Strapi 4.5.4 because of this.
Change in story to check the error - just added a button to set the value programmatically, which starts the issue.