I am using this library called react-native-multi-slider to implement a multi slider for a mobile application using React Native.
I was going through the example in the repository and found something odd that works somehow.
There are functions without any variable declaration in the code.
const [multiSliderValue, setMultiSliderValue] = React.useState([3, 7]);
const [sliderOneChanging, setSliderOneChanging] = React.useState(false);
sliderOneValuesChangeFinish = () => setSliderOneChanging(false);
multiSliderValuesChange = values => setMultiSliderValue(values);
I initially thought this was a mistake but I used the code in my application and it works without any runtime errors and these "functions" work as intended.
For example, multiSliderValuesChange
sets the values that are passed into it to setMultiSliderValues()
and when I log the values of multiSliderValue
it does match the values on the slider.
multiSliderValuesChange
is passed in as a prop to onValuesChange
which is a callback to update the values when they change, as per the documentation.
<MultiSlider
values={[multiSliderValue[0], multiSliderValue[1]]}
sliderLength={250}
onValuesChange={multiSliderValuesChange}
min={0}
max={10}
step={1}
allowOverlap
snapped
customLabel={CustomLabel}
/>
I went into the type definitions file of the MultiSlider
component and onValuesChange
takes as input an array of numbers and returns nothing:
onValuesChange?: (values: number[]) => void;
But I still do not understand how it works without any variable declarations such as var
, let
or const
.