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: format does not changes reactively #3222

Closed
1 of 3 tasks
Sovgut opened this issue Jan 13, 2025 · 1 comment
Closed
1 of 3 tasks

DatePicker: format does not changes reactively #3222

Sovgut opened this issue Jan 13, 2025 · 1 comment
Labels

Comments

@Sovgut
Copy link

Sovgut commented Jan 13, 2025

Description

When user select another format, as example using external selector, DatePicker does not update format after that change, only on initialization or when value changed.

Link to Reproduction (or Detailed Explanation)

https://codesandbox.io/p/devbox/admiring-water-53tz6h

Steps to Reproduce

  1. Select any other format using selector
  2. DatePicker does not have updated format value

Ark UI Version

4.8.0

Framework

  • React
  • Solid
  • Vue

Browser

Google Chrome

Additional Information

No response

@Sovgut Sovgut added the triage label Jan 13, 2025
@segunadebayo
Copy link
Member

We recommend using latest or live ref when referencing external variables in callbacks.

  const formatRef = useRef(format)
  formatRef.current = format

  const buildFormat = useCallback(
    (date: any) => {
      switch (formatRef.current) {
        case "month":
          return `${date.month}/${date.year}`;
        case "year":
          return `${date.year}`;
        default:
          return `${date.day}/${date.month}/${date.year}`;
      }
    },
    []
  );

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

No branches or pull requests

2 participants