search

Home  >  Q&A  >  body text

javascript - How does the react Modal method in Ant Financial insert elements to the end of the page?

I want to use react to write a public pop-up module, similar to the react Modal method of Ant Financial.

I don’t know what the principle of this implementation is? How can I insert the pop-up window I wrote into the end of the page?


大家讲道理大家讲道理2754 days ago1195

reply all(4)I'll reply

  • 迷茫

    迷茫2017-07-05 11:00:47

    Look at the source code of Modal implementation, it’s easy to understand. To put it simply:

    let p = createElement('p');
    document.body.appendChild(p);
    ReactDOM.render(<Modal />, p);

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 11:00:47

    @ssruoyan
    How can you implement this using ES6 syntax?

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-07-05 11:00:47

    Whether the modal is visible depends on its visibility. This is a mobile code written today. Not sure what you mean

    reply
    0
  • typecho

    typecho2017-07-05 11:00:47

    In fact, it is rendered out of the react scope and uses a component

    This involves the ReactDOM.unstable_renderSubtreeIntoContainer interface,
    But this interface is not available in the documentation and is marked unstable

    Its signature is like this

    function(
        parentComponent,
        nextElement,
        container,
        callback,
      )

    Probably can be used like this

    componentDidMount() {
        const container = document.createElement('p');
        document.body.appendChild(container);
        
        ReactDOM.unstable_renderSubtreeIntoContainer(
          this,
          (<Modal />),
          container,
          function () {
              /* callback */
          }
        )
    }

    For specific usage, please refer to the usage in react-portal
    or the usage in ant design of Ant Financial

    The signature and definition can be found here, with comments on it

    Actually, I don’t fully understand the usage of this interface... I’m not sure it’s correct. You should read the code in the link above by yourself

    reply
    0
  • Cancelreply