react-native-slider
react-native-slider copied to clipboard
Why does onValueChange return an array?
Here's an example of my implementation:
<Slider
value={2}
step={1}
maximumValue={4}
onValueChange={value => {
// why is this an array?
value = Array.isArray(value) ? value[0] : value;
setValue(value);
}}
thumbTintColor={secondaryTextGray}
minimumTrackTintColor={secondaryTextGray}
maximumTrackTintColor={dividerBorderGray}
/>
-
value={[0, 100]}
=>value
will be an arrayonValueChange={(value: number[]) => { console.log(value[0] , '<=>', value[1]) }}
-
value={100}
=>value
will be a numberonValueChange={(value: number) => { console.log(value) }}
That was the behavior I expected as well, the 2nd example here does not occur though. Here's a snack with what I am describing being reproduced (view the logs). https://snack.expo.dev/@justinadkins/slider-array-behavior
I can confirm this. I am also always receiving an array
Hi there,
My onValueChange
is also receiving an array, even when value
is a single number.
Also does onSlidingComplete
. Actually, all the functions that receive a changed value.
This does make more sense that how it works today. This would be a breaking change at this point, though so we'd have to bump to v3.
Do you all feel strongly about this change?
It's not really an issue, but it would be nice if the doc didn't specify the default as number
I've updated the types to reflect the actual callbacks are just arrays of numbers.
https://github.com/miblanchard/react-native-slider/commit/1e9b84052bcef3403484fdb86e451c9c0b196f2f
Going to close this as intended behavior at this time.