简体   繁体   中英

Loading React Component From button click on Extjs

I am currently working on integrating react project with existing extjs project.The requirement is to load a react component in an extjs page when a button is clicked, button resides in ext project

It is not so easy but you can begin from the following small code:

Ext.create('Ext.panel.Panel', {
    title: 'Hello',
    width: 200,
    height: 300,
    dockedItems: [{
        xtype: 'toolbar',
        items: [{
            text: "Load React Component",
            handler: function () {
                const panel = this.up('panel');
                const e = React.createElement;
                ReactDOM.render(
                    e('div', null, 'React'),
                    panel.body.el.dom
                );
            }
        }]
    }],
    renderTo: Ext.getBody()
});

and index.html

<HTML>
<HEAD>
    <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
    <!-- for Production -->
    <!--<script src="https://unpkg.com/react@16/umd/react.production.min.js" crossorigin></script>-->
    <!--<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js" crossorigin></script>-->
</HEAD>
<BODY>
</BODY>

Fiddle

Or you create a div with some ID in extjs panel's body using template or htmn property of panel and render your react project there.

PS it is very bad idea to integrate extjs with react.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM