I'm creating a custom library for React Native. I initiated the library using react-native-create-library. The library has not any native code. It's just written in typescript. At some places, I need to use react-native packages like react-native-bip39 and react-native-libsodium. But when I import any one of them it doesn't work, instead, it gives error that .default.function() is undefined or null.
How I can import such libraries into my project.
Related
I'm creating a react native library of components. This library will include typography. How can I include a font with this library? So that when I go to import the library into another react native project the font is automatically installed?
I know if I was using expo I could use expo-font to async import fonts. Is there a way of doing this without expo?
I have created a react native project and I want to save my UI components on a separate library for reusability. I have created an library mentioned here on the docs but found no proper guidance about package.json, example folder and how does a react-native library works.
I want to publish a react native library to npm with native codes (Java and Objective C). I have created a react native app and the native modules and native UI components are working fine in the app but I don't know how to publish my code as a react native library.
If you have completed all the tests, you can do this with a simple library.
that is create-react-native-library
This is shown in the official document of react-native.
You can also use create-react-native-module, a library with multiple added functions based on react-native-create-library
I am trying to use SliderButton, I recently installed slider-button in my terminal,
npm install --save react-native-slider-button
and tried to import it, but somehow it did not work.
on website, I am supposed to write
var SliderButton = require("react-native-slider-button");
but my react-native is latest ver so i am guessing that I probably should not use require, how do I write code with using "import"?
You can replace require with import by placing the following at the top of your file:
import SliderButton from "react-native-slider-button"
export default class MyComponent extends Component {
...
}
You can't really just "import" this particular component. It was written using an earlier implementation of JS called CommonJS which is used in NodeJS. React Native now uses ES6 for module management. The SliderButton Component is a little problematic. First, it uses the CommonJS module syntax inside the component itself, including loading React and React Native in ways that are no longer supported. So parts of this module would have to be rewritten to work with current versions of react native. You could roll back to a previous react native version that supports CommonJS, or you could modify the Component to use the ES6-style module importation.
I have a library that is written in TypeScript, that then has been compiled into one js file as an amd module.
I'm then trying to import { Stuff } from 'that/library'
but get an error message: Can't find variable: define;
can I not used AMD modules to import into my RN app?
bonus question: what bundling mechanism is used under the bonnet in react-native, it's clearly not Webpack..? and what types of modules are supported.
edit: just tried to recompile my library as System type module, that does not get recognised either react native: can't find variable: System;
React Native uses it's own packager, which relies on CommonJS (and ES6 Imports, transpiled by babel to, you guessed it, CommonJS). This answers both questions, UMD is not supported. There are different starter kits using webpack, though, if you would like to use it, for example this one.