Я пытаюсь получить доступ к элементу внутри модального (mui модальный) с помощью ссылки в реакции, но ссылка на элемент является нулевым - PullRequest
0 голосов
/ 27 марта 2020

Я пытаюсь получить доступ к компоненту, который монтировал метод жизненного цикла, но он показывает ноль Если я удаляю модал, он работает как положено, но внутри модальной ссылки не работает должным образом. Спасибо. Я пытался следовать, но он всегда показывает ноль.

import React, { Component } from "react";
import {
  Modal,
  Backdrop,
  Fade,
  Container
} from "@material-ui/core";
import { contactUsFormSchema } from "../../constant/FormValidation";

class ContactUs extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
    this.rootRef = React.createRef();
    this.childRef = React.createRef();
    this.observer = new IntersectionObserver((entries)=>{
      console.log(entries[0]);
    },{
      root:this.rootRef.current
    });
  }

  componentDidMount(){
    console.log(this.childRef.current); // this is always null
    console.log(this.rootRef.current); // this is always null
    // this.observer.observe(this.childRef.current);
  }

  render() {
    const { classes } = this.props;
    return (
      <Modal
        open={true}
        onClose={this.props.handleClose}
        closeAfterTransition
        BackdropComponent={Backdrop}
        BackdropProps={{
          timeout: 500
        }}

      >
          <Container className={classes.modalStyle}  ref={this.rootRef}>
            <div className={classes.title} ref={this.childRef} >Contact US</div>
          </Container>
      </Modal>
    );
  }
}

export default ContactUs;
...