[英]How to use react-rangeslider in a stateless component
now in a simple example in react-rangeslider as below现在在 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}
/>
)
}
}
if i change this into a stateless component如果我将其更改为无状态组件
return (
<Slider
value={props.volume}
orientation="vertical"
onChange={props.handleOnChange}
/>
)
and i am handling my state and onChange method in a different state-full component how to i pass the value to the handleOnChange method ?并且我正在不同的全状态组件中处理我的状态和 onChange 方法如何将值传递给 handleOnChange 方法?
handleOnChange = (value) => {
this.setState({
volume: value
})
}
that's the library i am using https://www.npmjs.com/package/react-rangeslider那是我正在使用的库https://www.npmjs.com/package/react-rangeslider
you can do something like this and pass the function and the state from the another component as props.你可以做这样的事情,并将另一个组件的函数和状态作为道具传递。
import React, { Component } from "react";
import Slider from "react-rangeslider";
const VolumeSlider = ({onChange,value}) => {
return <Slider value={value} orientation="vertical" onChange={onChange}/>;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.