Value is being updated while picking
See original GitHub issueThe problem:
value
props is being updated, even if picker is open. The use case is below.
The component:
function MyComponent ({ onChange, mode }) {
const [value, setValue] = useState(new Date());
useEffect(() => {
setTimeout(() => setValue(new Date(+ value + 60 * 60 * 1000)), 5000);
}, []);
return (
<DateTimePicker
value={value}
mode={mode}
onChange={onChange}
/>
);
}
The scenario:
<MyComponent mode="time" onChange={...} />
is rendered- During first 3 seconds, pick hours and wait on minutes screen
- Wait another 2 seconds
- Selected hours suddenly has been changed
Environment info
Tested only on Android
react-native info
output:
System:
OS: Windows 10 10.0.19041
CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
Memory: 4.55 GB / 15.85 GB
Binaries:
Node: 12.18.0 - ~\AppData\Local\Temp\yarn--1596125151497-0.3420221356958104\node.CMD
Yarn: 1.22.4 - ~\AppData\Local\Temp\yarn--1596125151497-0.3420221356958104\yarn.CMD
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6392135
Languages:
Java: Not Found
Python: 2.7.16 - /c/Python27/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: ~0.62.2 => 0.62.2
npmGlobalPackages:
*react-native*: Not Found
Library version: 2.6.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top Results From Across the Web
c# - What's the best way to handle updates only when a value ...
No. No. All the no! Firstly, don't make your callers do all that work! When I want to set a value, I just...
Read more >Pick Observable latest value when any value is produced by ...
Everytime the event sequence produces a new value, I want to pick (I'd say sample, but that might lead to confusion) the latest...
Read more >VBA Selection Change event picking up new value instead of ...
I'm tracking the value of a cell using the Worksheet Selection Change event and storing it in a variable. I'm then using a...
Read more >SBL-DAT-00590 Error While Trying to Pick A Value For A ...
1. Navigate to Asset > Campaign screen. ... 3. The above mentioned errors occurs. 4. Again click on click "new button" in Campaign...
Read more >How to UPDATE from a SELECT statement in SQL Server
The full update statement is used to change the whole table data with the same value. 1. 2. UPDATE table.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Im also having this problem using the downstream component
react-native-modal-datetime-picker
. See https://github.com/mmazzarolo/react-native-modal-datetime-picker/issues/451Ive looked at the code and from what I can tell every render it will call
picker.open()
which I’m guessing is causing the issue. This should only be called once (on initial render). https://github.com/react-native-community/datetimepicker/blob/master/src/datetimepicker.android.js#L46Maybe put this inside a useEffect or similar which only executes on initial load (or perhaps value change).
This issue would also be able to be worked around if onChange was called every time that the user clicks a date in the UI (its currently only called on clicking ok). This would mean that the latest value could be passed back into the component (so when it re-called open it would at least do so with the latest date the user selected)
Yep, this is exactly the problem 😃
I have kind of digital clock app. Something like:
In this example
useTime
hook is being updated each second, which means wholeClock
component is also being updated each second.It should be possible for user to “jump in time” (+/- a couple of hours) by click on
<TouchableOpacity>
. And this is where everything breaks. User sees the picker, but cannot select any time from it.