question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DateTimePicker] crashes with hooks-out-order error from React

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When I implement a DateTimePicker that can be set to read-only (not open the dialog) or editable dynamically like it is done here, setting the open property dynamically will cause an error like this:

Warning: React has detected a change in the order of Hooks called by PickerWithState. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useContext                 useContext
2. useContext                 useContext
3. useState                   useCallback
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    in PickerWithState (at App.tsx:14)
    in MuiPickersUtilsProvider (at App.tsx:40)
    in div (at App.tsx:28)
    in App (at src/index.tsx:7)

Expected Behavior 🤔

The DateTimePicker component should just be re-rendered as read-only or not. It would be great if there was a readOnly prop in the component out of the box.

Steps to Reproduce 🕹

Setup in a Sandbox here: https://codesandbox.io/embed/materialui-readonly-datepicker-klttf

Steps:

  1. Click the checkbox
  2. See Console Errors
  3. If you want, comment out the code that “crashes” and uncomment the one that doesn’t.
  4. It will work as expected in that scenario.

Alternatively, clone this repo: https://github.com/agonzalezjr/materialui-readonly-datepicker (it’s just a create-react-app ... --typescript with MaterialUI installed and App.tsx modified to reproduce the issue.

npm i
npm run start

In the main web page, click the checkbox.

Context 🔦

A DateTimePicker that can be set to read-only dynamically. It would be great if there was a readOnly prop in the component out of the box.

Your Environment 🌎

Tech Version
Material-UI v4.4.0
React v16.9.0
Browser Chrome v76.0.3809.132
TypeScript v3.5.31
@material-ui/pickers v3.2.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dmtrKovalenkocommented, Sep 4, 2019

You must not change open property to undefined dynamically. If you need to - please implement your own state for open prop.

0reactions
agonzalezjrcommented, Sep 6, 2019

Ok, that works! Thank you so much!

I have updated the sandbox with the fixed code https://codesandbox.io/s/materialui-readonly-datepicker-klttf

Read more comments on GitHub >

github_iconTop Results From Across the Web

[DateTimePicker] crashes with hooks-out-order error from React
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >
React crashes without displaying error when user selects one ...
Found it. Selecting 'now' was saving a date as a moment object in state. Datepicker caused react to crash when it tried to...
Read more >
react-native-date-picker - npm
A datetime picker for React Native. In-modal or inlined. Supports Android and iOS.. Latest version: 4.2.6, last published: 2 months ago.
Read more >
Debugger crashes on DateTimeChanged event
I placed a new DateTimePicker and copied the code. And still when I put the debugger stop at dateDTP_ValueChanged it will stop there...
Read more >
Browser hangs when using datepicker
It says "Sorry, something went wrong" once you pick a date. It hangs the browser for long time, 10-20 seconds, then puts up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found