Estoy usando una biblioteca de javascript llamada nextparticle. Estoy tratando de implementarlo en React.js. Busqué por todas partes y probé todas las opciones, pero no puedo hacer que funcione. Intenté esto.
import React, {Component } from 'react' import { NextParticle } from '../nextparticle'; import {Helmet} from "react-helmet"; const Background = () => ( <div> <Helmet> <script src="../nextparticle.js" type="text/javascript" /> </Helmet> <NextParticle /> </div> );este es el error que tengo
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. También intenté import NextParticle from '../nextparticle'; Tampoco funciona. Lo he intentado durante días. Debo pasar parámetros especiales para que esto funcione. Cualquier parámetro que intento poner no hace nada. Así es como debería verse
<img id="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/23500/nextparticle.png" /> <script src="https://nextparticle.nextco.de/nextparticle.min.js"></script> <script> nextParticle = new NextParticle({ image: document.all.logo, addTimestamp: true, width: window.innerWidth, height: window.innerHeight, initPosition: 'none', initDirection: 'none', }); }); window.onresize = function () { if (window.innerWidth > 600) { nextParticle.width = window.innerWidth - 20; nextParticle.height = window.innerHeight - 20; nextParticle.start(); } }; </script>También agregué esto en mi index.html
<script src="/nextparticle.min.js"></script>De nuevo, sin resultados. esta es la documentación para la biblioteca Cualquier ayuda es apreciada, gracias.
Supongo que tienes que export tu componente de fondo, ya que eso es lo que menciona el error.
import React, {Component } from 'react' import { NextParticle } from 'nextparticle'; import {Helmet} from "react-helmet"; export const Background = () => ( <div> <Helmet> <script src="../nextparticle.js" type="text/javascript" /> </Helmet> <NextParticle /> </div> ); Y si desea importar un script de terceros en React , impórtelo directamente en su index.html . Por lo general, en el directorio public . A menos que realmente necesites un Helmet .