【发布时间】:2020-01-13 18:48:32
【问题描述】:
现在在 react-rangeslider 中的一个简单示例如下
import React, { Component } from 'react'
import Slider from 'react-rangeslider'
class VolumeSlider extends Component {
constructor(props, context) {
super(props, context)
this.state = {
volume: 0
}
}
handleOnChange = (value) => {
this.setState({
volume: value
})
}
render() {
let { volume } = this.state
return (
<Slider
value={volume}
orientation="vertical"
onChange={this.handleOnChange}
/>
)
}
}
如果我把它改成无状态组件
return (
<Slider
value={props.volume}
orientation="vertical"
onChange={props.handleOnChange}
/>
)
我正在另一个状态完整组件中处理我的状态和 onChange 方法,我如何将值传递给 handleOnChange 方法?
handleOnChange = (value) => {
this.setState({
volume: value
})
}
【问题讨论】:
标签: javascript reactjs jsx