What is the recommended way to use native javascript libraries in react native? Are there any specific restrictions?
If you specifically want to use moment.js in react or react native, have a look at react-moment
, a react component for the moment library, at https://github.com/headzoo/react-moment.
To use react-moment in react native, run:
npm install --save moment react-moment
Then in the file you want to use moment:
import Moment from 'react-moment';
Finally, use it as desired, for example:
{ post.datePublished }
The prop element={Text}
is specifically for react native. It ensures that the resulting string is rendered in a Text
component. Without this, react native would throw an error.