我只是学习反应,并希望实现一个功能: A,B都是组件,如果是A滚动,那么B滚动
以下是我的代码
<A onScroll="handleScroll"></A>
//what i write now
handleScroll: function(event){
var target = event.nativeEvent.target;
//do something to change scrollTop value
target.scrollTop += 1;
// it looks the same as not use react
document.getElementById(B).scrollTop = target.scrollTop;
}
Run Code Online (Sandbox Code Playgroud)
但实际上我想要这样的代码
//what i want
<A scrollTop={this.props.scrollSeed}></A>
<B scrollTop={this.props.scrollSeed}></B>
//...
handleScroll(){
this.setState({scrollSeed: ++this.state.scrollSeed})
}
Run Code Online (Sandbox Code Playgroud)
它类似于 input
<input value="this.props.value"/>
<input value="this.props.value"/>
<input ref='c' onChange={handleChange}>
//...
handleChange: function() {
// enter some code in c and then render in a and b automatically
}
Run Code Online (Sandbox Code Playgroud)
换句话说,我想要一些属性,比如scrollTop …