Javascript 这个.base在preact中是什么意思?

Javascript 这个.base在preact中是什么意思?,javascript,reactjs,react-native,preact,Javascript,Reactjs,React Native,Preact,能否此.base引用Preactjs中的当前组件? 我有一个代码,上面有一行 const rect = this.base.getBoundingClientRect(); this.base是对当前组件的根DOM元素的引用 它是组件的render函数返回的JSX元素 因此,一旦安装了组件,就可以使用this.base 以下是一个小的生命周期示例: 类示例扩展组件{ shouldComponentUpdate(){ //不要通过差异重新渲染: 返回false; } 组件将接收道具(下一步){

能否此.base引用Preactjs中的当前组件? 我有一个代码,上面有一行

const rect = this.base.getBoundingClientRect();

this.base
是对当前组件的根DOM元素的引用

它是组件的
render
函数返回的JSX元素

因此,一旦安装了组件,就可以使用
this.base

以下是一个小的生命周期示例:

类示例扩展组件{
shouldComponentUpdate(){
//不要通过差异重新渲染:
返回false;
}
组件将接收道具(下一步){
//如果你需要的话,你可以在这里用新来的道具做点什么
}
componentDidMount(){
//现在已安装,可以自由修改DOM:
让thing=document.createElement('maybe-a-custom-element');
这个.base.appendChild(东西);
}
组件将卸载(){
//组件即将从DOM中删除,请执行任何清理。
}
render(){
返回;
}
}
class Example extends Component {
  shouldComponentUpdate() {
    // do not re-render via diff:
    return false;
  }

  componentWillReceiveProps(nextProps) {
    // you can do something with incoming props here if you need
  }

  componentDidMount() {
    // now mounted, can freely modify the DOM:
    let thing = document.createElement('maybe-a-custom-element');
    this.base.appendChild(thing);
  }

  componentWillUnmount() {
    // component is about to be removed from the DOM, perform any cleanup.
  }

  render() {
    return <div class="example" />;
  }
}