How can I use javascript library such as moment.js in react native

后端 未结 5 2006
臣服心动
臣服心动 2021-02-06 20:13

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

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 20:44

    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();
    

    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

提交回复
热议问题