2021年1月15日星期五

Change the value of Component via ref

I am using Material-UI with React

I have Slider and want to set the value.

class ParamBoard extends React.Component{     constructor(props) {       this.sliderRef =  React.createRef();     }     componentDidMount() {       this.sliderRef.current.value = 1 // not work.     }     this.hugaRef = React.createRef();      render(){        return (          <Slider step={1} min={1} max={6} marks width={1/4 } ref="{this.sliderRef}"          aria-labelledby="continuous-slider" />)         )      }  }  

Normally with jQuery I do like this ('#myslider').value(2) to get the dom and change the value.

However in Reactjs I thought I should use ref??? is it correct or how can I fix this ??

https://stackoverflow.com/questions/65745817/change-the-value-of-component-via-ref January 16, 2021 at 10:06AM

没有评论:

发表评论