简体   繁体   English

React Native - 从 cdn 运行脚本

[英]React Native - run script from cdn

Is there a way to run a script from a cdn in react-native?有没有办法在 react-native 中从 cdn 运行脚本?

For example in ReactJS:例如在 ReactJS 中:

 //index.html
 <script
  type="text/javascript"
  src="https://js.xendit.co/v1/xendit.min.js"
 ></script>

 //react component file
 const Xendit = window.Xendit;
 const Component = ({card_number}) => {
     const[cardNumberValidated, setCardNumberValidated] = useState(false);
     useEffect(() => {
        const isValidated = Xendit.card.validate(card_number);
        setCardNumberValidated(isValidated)
     },[])
     ...
 }

I tried downloading the file and saving it locally, but it doesn't work我尝试下载文件并将其保存在本地,但它不起作用

saved file
Xendit.min.js

//import
import Xendit from '@myUtils/Xendit.min';
import {KEY} from '@myUtils/XenditUtils';

//call it
Xendit.setPublishableKey(KEY)
//it returns Xendit.default.setPublishableKey is not a function

Use xendit-js-node使用xendit-js-node

...
import Xendit from 'xendit-js-node';
...
Xendit.setPublishableKey('xnd_public_development_OYqIfOUth+GowsY6LeJOHzLCZtSj84J9kXDn+Rxj/mbf/LCoCQdxgA==');
...
Xendit.card.createAuthentication(threeDSData, this._tokenResponseHandler);
...
//etc.

There is an official example React Native app: https://github.com/xendit/xendit-react-example有一个官方示例 React Native 应用程序: https : //github.com/xendit/xendit-react-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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