vasturiano / react-force-graph

React component for 2D, 3D, VR and AR force directed graphs
https://vasturiano.github.io/react-force-graph/example/large-graph/
MIT License
2.03k stars 263 forks source link

[Typescipt Import] #312

Open SherloqueChang opened 2 years ago

SherloqueChang commented 2 years ago

For the example given in Github, .js files are imported in HTML using like:

  <script src="//unpkg.com/react/umd/react.production.min.js"></script>
  <script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
  <script src="//unpkg.com/babel-standalone"></script>

However, if I'd like to import them in a react+typescript project, what should I do?

vasturiano commented 2 years ago

If you're using ES modules, you can just do f.e.

import ForceGraph3D from 'react-force-graph-3d';

There's more info about importing this module in the readme.

SherloqueChang commented 2 years ago

Yead, it works for 'react-force-graph-3d'. However, here is a specific example: https://github.com/vasturiano/react-force-graph/blob/master/example/text-links/index-3d.html#L28 Since I don't how to deal with<script src="//unpkg.com/three-spritetext"></script> in a .tsx file, error 'Cannot find name 'SpriteText'' is reported.

vasturiano commented 2 years ago

That's for an import from another module: https://github.com/vasturiano/three-spritetext