簡體   English   中英

React-Bootstrap Modal渲染兩次

[英]React-Bootstrap Modal rendering twice

我使用了React-Bootstrap Modal,但不明白為什么Foo組件渲染兩次?

import { Modal, Button } from 'react-bootstrap';

const Foo = (props) => {
  console.log(‘a’);
  return(
    <div>foo</div>
  )
}

class Example extends Component {
  render() {
    return(
      <Modal show={true}>
        <Foo />
      </Modal>
    )
  }
}

進入模態時,Bootstrap模態集看起來像狀態(即使show最初像上面一樣設置為true)。 請參閱https://github.com/react-bootstrap/react-bootstrap/blob/master/src/Modal.js#L202-L209 因此,將再次觸發渲染,從而使Foo渲染兩次。

編輯:實際上,您必須完全回到React-transition-group,以了解為什么實際上會調用onEntering函數。 https://github.com/reactjs/react-transition-group/blob/master/src/Transition.js#L192 在componentDidMount上,調用this.updateStatus,最終調用onEntering。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM