Call external Javascript function from react components

前端 未结 4 1954
南旧
南旧 2020-12-08 14:32

Im not sure if this has been asked before or anybody has encountered the same issue on reactjs. So the scenario is like this, I have an index.html file that include

4条回答
  •  Happy的楠姐
    2020-12-08 14:53

    So either you define the method on global scope (aka window). And then you can use it from any methods, being React or not.

    Or you can switch to module based paradigm and use require/import to get the module and use the function.

    For bigger projects the latter is better as it's scales, while if you need a demo or POC you can certainly hook all to global scope and it will work.

    More information about modules is at: http://exploringjs.com/es6/ch_modules.html

提交回复
热议问题