如何在 React Native 中使用诸如 moment.js 之类的 javascript 库 [英] How can I use javascript library such as moment.js in react native

查看:28
本文介绍了如何在 React Native 中使用诸如 moment.js 之类的 javascript 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 React Native 中使用原生 JavaScript 库的推荐方法是什么?有什么具体限制吗?

What is the recommended way to use native javascript libraries in react native? Are there any specific restrictions?

推荐答案

Easy peasy!从项目的根目录运行:

Easy peasy! From the root of your project just run:

npm install moment --save

然后你可以在你的代码中导入它:

Then you can import it in your code:

import moment from 'moment';
var now = moment().format();

限制是任何试图接触"浏览器的东西(在这种情况下不存在).这就是为什么有像 XHR 这样的东西的 polyfill.

The restrictions would be anything that tries to "reach out" to the browser (which doesn't exist in this context). That's why there's polyfills for things like XHR.

官方文档有关于如何使用矩库的示例

The official documentation has examples on how to use the moment library

这篇关于如何在 React Native 中使用诸如 moment.js 之类的 javascript 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆