Can you explain how to incorporate a node module script into a React.js project?

I have encountered an issue where the element works perfectly fine when using an external node module, but fails to function properly when using a locally downloaded node module. Unfortunately, I am unable to identify the root cause of this problem.

You can find the Swipi-cards library here.

Although my code is working as expected, once I switch to using a local node module as the source, it stops functioning. Any suggestions for potential fixes?

import React, { useState, useEffect } from 'react';
import Data from '../Data/webApps_data';

function Webapps() {

    const [loading_animation, setloading_animation] = useState(false);
    const [arrayChecker, set_arrayChecker] = useState(0);

    useEffect(() => {
        if (loading_animation === false) {
            setTimeout(() => {
                setloading_animation(!loading_animation);
                console.log()
            }, 100);
        }

        const script = document.createElement('script');
        script.src = "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92e1e5fbe2fbbff1f3e0f6e1d2a3bca2bca2">[email protected]</a>/dist/swipi-cards/swipi-cards.js";

        script.async = true;

        document.body.appendChild(script);

        return () => {
            document.body.removeChild(script);
        }
    }, [loading_animation]);

    const arrayLimiter = () => {
        if (arrayChecker < (Data.length - 1)) {
            set_arrayChecker(arrayChecker + 1)
        } else {
            set_arrayChecker(0)
        }
        console.log(Data);
    };

    const filteredData = Data[arrayChecker];
    const textTransition = loading_animation ? 'text_transition ease' : 'text_transition';
    const elementTransition = loading_animation ? 'element_transition ease' : 'element_transition';

    //swipicard script

    return (
        <div className='webAppStyles'>
            <rg-swipi-cards stack-offset-y="0.3" class='hydrated'>
                <rg-swipi-card left-color='green' right-color='green' class='hydrated'>
                    <p>test1</p>
                </rg-swipi-card>
                <rg-swipi-card left-color='green' right-color='green' class='hydrated'>
                    <p>test2</p>
                </rg-swipi-card>
            </rg-swipi-cards>
        </div>
    )

}

scss styles:
 rg-swipi-cards {
        display: flex;
        align-self: center;
        background: chocolate;
        width: 350px !important;
        height: 400px !important;
        align-items: center;
        justify-content: center;
        rg-swipi-card {
            width: 100%;
            position: absolute;
            transition: all 0.5s ease-in-out 0s;
            z-index: 4;
            opacity: 1.33333;
        }
        p {
           text-align: center;
        }
}

Answer №1

After experimenting with this source, it appears to be functional. However, I am puzzled as to why the node module isn't working. Any thoughts on what might be causing this issue?

 script.src = "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1c18061f06420c0e1d0b1c2f5e415f415f">[email protected]</a>/dist/swipi-cards/swipi-cards.js";

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The internet browser encountered a JavaScript runtime error (0x800a138f) in which it was unable to retrieve property '0' due to it being either undefined or pointing to a

I'm encountering an issue with my javascript/jquery function that retrieves the selected dropdown value. Everything works fine in Chrome, but when I try to run my application in IE, it throws an error. $("#Application_AppCountries").change(function ( ...

Loop through JSON data using jQuery for parsing

Here is the code snippet I have included below, which is a part of a larger code base: <html> <head> <style> #results{margin-top:100px; width:600px; border:1px solid #000000; background-color:#CCCCCC; min-height:200px;} </style> & ...

Testing components in Angular using Renderer2

Recently, I came across an Angular component with the following structure: constructor( @Inject(INJECTION_TOKEN_WINDOW) private window: Window, private renderer: Renderer2 ){} ngOnInit() { this.renderer.addClass(this.window.document.body ...

Different approach for searching and modifying nested arrays within objects

Here is an example of the object I am working with: { userId: 111, notes: [ { name: 'Collection1', categories: [ { name: 'Category1', notes: [ {data: 'This is the first note& ...

The reason why Type zzz cannot be assigned to type (zzz & NgIterable<xxx>) | undefined | null

Why am I receiving the message in Angular 9 that says: Type Items is not assignable to type (Items & NgIterable) | undefined | null? Despite the fact that the model is correct and there are no errors in the data, I still encounter this TypeScript warn ...

When attempting to host a React application within an Express server, an error is encountered with the message "

I am looking to host my react app, created with create-react-app, using an express app. This is the express app I have written: const express = require('express') const path = require('path') const app = express() console.log(path.re ...

Obtaining a variable from HTML and passing it to Node.js

Currently, I am utilizing express to handle form submissions. Within my HTML file, there are 20 inputs with unique ids such as address1, address2, address3, and so on. In my node js code, I access these input values using req.body.address1. Users have th ...

What is the reason for jQuery displaying undefined when attempting to retrieve a custom data attribute using .prop()?

In my dynamic HTML generated by JavaScript, the following code snippet is included: $(".task-status").live("click", function () { alert("data-id using prop: " + $(this).prop("data-id")) alert("data-id using data: " + $(this).data("id")) ...

What is the reason for sending a JSON string in an HTTP POST request instead of a JavaScript object in AngularJS

When sending data via a post request in AngularJS, the code may look like this: $http({ method: 'POST', url: url, data: inputParams, headers: headers }) .then(function succes(response) { successCallBack(response.data); } Here is h ...

Unlocking numerical input solely by executing the specified command within the most up-to-date iteration of the Chrome Extension of Selenium IDE

After executing the command in Selenium IDE, I successfully extracted the sentence, "Your booking ID is 1234", and saved it in a variable named myText. <table> <tr> <th>Command</th> <th>Target</th> < ...

How can I implement a GET request in NextJS 13.4 to fetch all items or by a specific ID? Should I use Response, NextAPIResponse, or NextResponse with the latest App Router features?

What is the proper method for performing a GET request (either to retrieve all items or by a specific ID) in NextJS 13.4 using the new App Router? The old approach of handling GET requests with NextAPIRequest, NextAPIResponse, checking if (req.method === ...

Finding the div associated with the element that triggered an event

I've recently launched a website that allows users to post questions and receive responses from others. Each question is housed in a div, which then contains another div with the CSS property of display: none. Within the main div, there's a butt ...

The compatibility issue between Vue 2.6.12 and Laravel is causing difficulties for FullCalendar to function properly

Recently, I attempted to integrate the fullcalendar library version 5.9.0 into my project following the instructions provided in the documentation. <script> import '@fullcalendar/core/vdom' // resolves Vite issue import FullCalendar from ...

Issue with ng-true-value in AngularJS version 1.6.1 - not functioning as expected

Recently, I delved into AngularJS and followed an online tutorial that showcased how to utilize ng-true-value and ng-false-value. Here's the snippet: <!DOCTYPE html> <html lang="en"> <head> <script src="https://ajax.googleapis ...

Is there a way to undo the click event in Javascript?

Is there a way to revert back to the initial position after clicking? I successfully changed the x icon to a + icon on click, but now I'm struggling to reverse that action. I've tried using MOUSEUP and DBLCLICK events, but they aren't ideal ...

What is the best way to shift all elements to the right side except for 'tindog'?

https://i.sstatic.net/hAUps.png <nav class="navbar navbar-expand-lg navbar-dark "> <a class="navbar-brand" href="">Tindog</a> <button class="navbar-toggler" type="button" data-t ...

Exploring the integration of Formik with Material-UI's select field - A step-by

Trying to implement Formik with Material-UI's Textfield component using the select attribute. Every time I change the option, it shows this warning: Material-UI: You have provided an out-of-range value null for the select (name="subIndicatorId& ...

Controller unable to access form inside ng-repeat loop in AngularJS

Looking to access a form object within my controller. The form is located inside an ng-repeat block with a dynamic name, and I should be able to access it since version 1.3. JavaScript: var app = angular.module('app', []); app.controller(' ...

Why is it that I am unable to retrieve a value from useContext?

How come I am unable to retrieve a value from useContext? I have already made an update. components/useContext/index.js import React, { useState } from "react"; import Article from "./article"; import status from "./status"; ...

Closing a batch file after the React app is shut down can be achieved by utilizing a

Running my react application involves the use of a .bat file with the following commands: cd.. cd projects cd material cd server npm run dev Upon executing this script, it initiates cmd and launches my app in Chrome. Despite spending hours searching for ...