JSX React HTML5 Input Slider Doesn't Work

后端 未结 5 1568
陌清茗
陌清茗 2021-01-31 02:48

I\'m using React.JS for a build, and am building a range input slider with two choices for a component.

this is my code:



        
5条回答
  •  生来不讨喜
    2021-01-31 03:33

    User interactions have no effect because an with value prop is considered as controlled. It means that displayed value is controlled entirely by render function. So to actually update input value you should use the onChange event. Example:

    getInitialState: function() {
      return {value: 3};
    },
    handleChange: function(event) {
      this.setState({value: event.target.value});
    },
    render: function() {
      return (
        
      );
    }
    

    You can also use defaultValue instead of value. In this case is considered as uncontrolled and any user interactions are immediately reflected by element itself without invoking render function of your component.

    More on this in official documentation

提交回复
热议问题