How to import JS library to typescript in React Native project
typescript import js file from node_modules
react typescript import js library
import third party js in typescript
react native'; import js file
How can I import js library (in my case xhook library) into my react native project written in typescript? Or How can I create typescript header file for external js library?
You can simply use:
const signalrLib = require("react-native-signalr").default
Sharing Code between React Web / Native TypeScript Projects, First include the library source file before the compiled TypeScript file of your project ,using script tag in your HTML file . Next ,In your TypeScript I want to import a js library(react-native-webview-bridge) in my react-native project.but my project use typescript,and the library is js.when i import it, it tips
So when you add example
xhook to your project, project owner has already compiled his/her TypeScript code into plain JS and you import it just like any other library.
import xhook from 'xhook' or so on how library author has specified.
You can see it yourself if you visit xhook's git page https://github.com/jpillora/xhook you can see compiled code in folder
dist and in
package.json -file, attribute
main points to that file.
edit. seems like
xhookis actually written in CoffeeScript but this same rule applies to it as well.
As suggested, You can use any ES6/ES2015 notation in typescript. With the new typescript, import will be
import xhook from 'xhook';
import * as xhook from 'xhook'
Some module doesnt have type support. You can look for type support as
yarn add @types/xhook
If you dont find type support you can use, node require syntax
const xhook = require('xhook');
For that you may have to declare, require definition like:
declare const require: any;
- See if this helps? github.com/philikon/ReactNativify