Can I use jsx without React to inline HTML in script?

后端 未结 8 1690
既然无缘
既然无缘 2021-01-31 02:20

Can I use inline HTML in a script as below by using a library like jsx:




        
8条回答
  •  再見小時候
    2021-01-31 02:54

    It looks like the dom-chef package can do this. From the readme:

    • No API, JSX gets auto transformed into actual DOM elements.

    // babel.config.js
    
    const plugins = [
      [
        '@babel/plugin-transform-react-jsx',
        {
          pragma: 'h',
          pragmaFrag: 'DocumentFragment',
        }
      ]
    ];
    
    // ...
    

    const {h} = require('dom-chef');
    
    const handleClick = e => {
        //  was clicked
    };
    
    const el = (
        
    );
    
    document.body.appendChild(el);
    

提交回复
热议问题