react ref获取元素高度

import ReactDOM from "react-dom";

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      width: 0
    };
  }

  componentDidMount() {
    const width = this.divElement.clientWidth;
    this.setState({ width });
  }

  render() {
    return (
      
(this.divElement = divElement)}> Size: {this.state.width}px but it should be 18px after the render
); } } const rootElement = document.getElementById("root"); ReactDOM.render(, rootElement);

 

你可能感兴趣的:(react,react)