AnA*_*ice 3 reactjs createreactclass
我想在React中使用这个包:https://github.com/naikus/svg-gauge
React的例子使用CreateReactClass如下:
我需要这个吗?他们为什么要用这个?文档没有提到使用背后的原因CreateReactClass.你能用这个包没有CreateReactClass吗?
import React from "react";
import CreateReactClass from "create-react-class";
import Gauge from "svg-gauge";
const defaultOptions = {
animDuration: 1,
showValue: true,
max: 100
// Put any other defaults you want. e.g. dialStartAngle, dialEndAngle, radius, etc.
};
const Component = CreateReactClass({
displayName: "Gauge",
componentDidMount() {
this.renderGauge(this.props);
},
shouldComponentUpdate(nextProps, nextState) {
const {props} = this;
if(props.value !== nextProps.value) {
this.renderGauge(nextProps);
}
return false;
},
render() {
return (
<div className="gauge-container" ref={el => this.gaugeEl = el}></div>
);
},
renderGauge(props) {
const gaugeOptions = Object.assign({}, defaultOptions, props);
if(!this.gauge) {
this.gauge = Gauge(this.gaugeEl, gaugeOptions);
}else {
this.gauge.setValueAnimated(props.value, gaugeOptions.animDuration);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5058 次 |
| 最近记录: |