React獲取組件實例


1. 直接new Component()

組件本身也是class,可以new,這樣的組件實例意義不大

componentInstance = new Component();

2. ReactDOM.render返回組件實例(React新版本已失效,返回null)

componentInstance = ReactDOM.render(<Component />, div);

3. ref回調函數返回組件實例(React新版本可用)

let componentInstance;

ReactDOM.render(<Component ref={(com) => componentInstance = com} />,div>)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM