New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slider onChange callback can't see states of calling component #3250
Comments
Slider onChange function is momoized to improve performance, it cannot reference state variables. |
I've found a workaround, you can use this component instead if memoization is making issues: import { Slider, SliderProps } from '@mantine/core'
import { useDidUpdate } from '@mantine/hooks'
function SliderNoMemo(props: SliderProps) {
const [value, setValue] = useState(props.value)
useDidUpdate(() => {
if (value) props.onChange?.(value)
}, [value])
useDidUpdate(() => {
setValue(props.value)
}, [props.value])
return <Slider {...props} value={value} onChange={setValue} />
} |
Duplicate of #2840 |
Not ideal but this worked and helped me. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What package has an issue
@mantine/core
Describe the bug
In Slider component when you use a custom callback in onChange prop that not only set a value but also uses internal states of calling component these states are invisible, undefined or 0.
The other Mantine components, Select for instance or the standard ones (input) can see calling component states in callback normally as it should be.
I hope it's a bug not a feature.
What version of @mantine/hooks page do you have in package.json?
5.9.5
If possible, please include a link to a codesandbox with the reproduced problem
No response
Do you know how to fix the issue
No
Are you willing to participate in fixing this issue and create a pull request with the fix
None
Possible fix
No response
The text was updated successfully, but these errors were encountered: