Slider props value changes not rendering correctly
See original GitHub issueHello,
I’m having problems with Slider every time props value changes. I have already update react-native-elements to last version (3.4.2) to resolve this bug #2995 but I’m still having problems. Now every time props value changes, the position of the thumb changes correctly but it seems props value is not changing. Here it is a video that explains it better.
To control Slider value, there is a parent component who stores in state the value and listens to every element that change this. Here it is the parent code:
import { View, StyleSheet } from 'react-native';
import { Button, Slider } from 'react-native-elements';
const LightDimmerDetailScreen = () => {
const [currentValue, setCurrentValue] = useState(0);
const handleOnSliderChange = (newValue: number) => {
setCurrentValue(newValue);
};
return (
<View style={styles.screen}>
<Slider
value={currentValue}
minimumValue={0}
maximumValue={100}
step={1}
minimumTrackTintColor={'red'}
onSlidingStart={(newSliderValue) => console.log('on sliding start: ', newSliderValue)}
onSlidingComplete={(newSliderValue) => handleOnSliderChange(newSliderValue)}
/>
<Button onPress={() => setCurrentValue(50)} title={'set to 50%'} />
</View>
);
};
export default LightDimmerDetailScreen;
const styles = StyleSheet.create({
screen: {
marginTop: 100,
width: 300,
marginHorizontal: 57,
},
});
I’m using:
- react-native-elements: 3.4.2
- react-native: 0.64.1
Thanks in advanced for your help!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top Results From Across the Web
React slider not rendering correctly - Stack Overflow
It seems like you forgot to import rc-slider CSS. import 'rc-slider/assets/index.css'. I tried to reproduce your issue here and removing ...
Read more >Docs • Svelte
Reactive statements run after other script code and before the component markup is rendered, whenever the values that they depend on have changed....
Read more >Uncontrolled Components - React
In the React rendering lifecycle, the value attribute on form elements will override the value in the DOM. With an uncontrolled component, you...
Read more >React slider tutorial using react-slider - LogRocket Blog
Learn how to create different sliders using react-slider, a React headless component that's easy to build and customize.
Read more >@react-native-community/slider - npm
Properties ; onSlidingComplete, Callback that is called when the user releases the slider, regardless if the value has changed. The current value ......
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
Also, I don’t know if this helps at all, but here’s the diff from our forked version which fixes this (I might try to apply it directly and PR, but unfortunately we de-typescript-ified the whole thing so it’s nearly impossible, but maybe it’s a starting place).
Basically:
Doing all this, the PanResponder won’t be recreated when you move the slider around, but will be recreated if its props change externally. Theoretically, this might cause issues if one of the callbacks causes a Slider prop (other than the value) to change (like maybe a style?), which seems like a less common case than just wanting the thing to update correctly.
Go for it