私は温度計のsvgを持っています。相互作用は、ユーザによって提供された値に従って針を動かすことである。値はレンジャーから提供することができ、温度計は針を動かすことによって更新する必要があります。状態が変化したときにニードルが更新されない
あなたはここで
https://www.webpackbin.com/bins/-Khv7qwzOc5OlYE9UY-1こっちは、私はあなたがの
height
と
y
値を設定するので、それを更新していない
componentDidMount(){
this.animationH.setAttribute('from', this.animationH.getAttribute('to'));
this.animationH.setAttribute('to', this.state.value);
this.animationY.setAttribute('from', this.animationY.getAttribute('to'));
this.animationY.setAttribute('to', this.state.value);
}
handleChange(event) {
this.setState({ value: event.target.value });
}
render() {
const {value} = this.state;
return (
<div>
<input
type="range"
min="1"
max="100"
step="1"
onChange={(event) => this.handleChange(event)}
/>
{value ? value : ''}
<svg width="133px" height="350px" viewBox="0 0 133 1113" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect id="Rectangle-2" stroke="#979797" strokeWidth="2.132" fill="#C20C0C" filter="url(#filter-1)" x="56.8899994" y="735" width="18" height="200">
<animate
attributeName="height"
from="0"
to="200"
fill="freeze"
dur="2s"
ref={(animationH) => this.animationH = animationH}
/>
<animate
attributeName="y"
from="935"
to="735"
fill="freeze"
dur="2s"
ref={(animationY) => this.animationY = animationY}
/>
</rect>
</svg>
</div>
);
}