简体   繁体   English

React App 中的外部 JS - 渲染问题

[英]External JS in React App - Rendering issue

I am new to react an trying to add external JS in react App.我是新手,试图在 React App 中添加外部 JS。 However no approach is working for me as JS does not work at all.但是没有任何方法对我有用,因为 JS 根本不起作用。

Below is my code.下面是我的代码。 What is wrong with the code?代码有什么问题?

import logo from './logo.svg';
import './App.css';
import React, { Component }  from 'react';
import * as Yup from 'yup';
import ScriptTag from 'react-script-tag';
import {Helmet} from "react-helmet";

function App() {
  return ( 
  <div className='App'>
    <h1>This is external javascript - Helmet</h1>
    <Helmet>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" 
    type="text/javascript" />
    </Helmet>
    
    <h1>This is external javascript - ScriptTag</h1>
      <ScriptTag isHydrating={true} type="text/javascript" 
      src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" />
    
  </div>
  );
}

export default App;

You cannot use jquery cdn directly inside the react js project.您不能直接在 react js 项目中使用 jquery cdn。 Rather you can go with the below plugin to use jquery inside your react js project,相反,您可以使用以下插件 go 在您的 react js 项目中使用 jquery,

https://www.npmjs.com/package/react-jquery-plugin https://www.npmjs.com/package/react-jquery-plugin

Just install it with below code,只需使用以下代码安装它,

npm install --save react-jquery-plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM