Equivalent of requiring a subproperty in ES6 import

后端 未结 2 853
旧时难觅i
旧时难觅i 2021-01-22 06:24

I have an existing require:

const {dialog} = require(\'electron\').remote;

I started using Babel for ES6, and would like to

2条回答
  •  粉色の甜心
    2021-01-22 06:59

    There is nothing 'ugly', it is how the things should be written in ES6.

    imports are supposed to be statically analyzed without script evaluation, supported syntax is limited. Default import can't be destructured in import statement, all varieties of syntax are listed in the reference.

    It can be written as

    import electron from 'electron';
    const { remote: { dialog } } = electron;
    

提交回复
热议问题