How to use javascript in react component
I'm working on a React component and I found a specific javascript code that modify the content of my html page.
The problem is that I don't know how to merge this script into my component. I know I can call it with an "import" statement but the script works with a "window.onload" function that will be called only one time, but my component is mounted several times and the script won't work anymore
The Component -
import React, { Component } from 'react';
import textRotation from '../../scripts/textRotation';
import './Main.scss';
class Main extends Component {
constructor(props) {
super(props);
this.title = props.title;
this.imgSrc = props.imgSrc;
}
render() {
return (
<div className="Main">
<div className="main-content">
<div className="presentation-caption">
<span>Hello, I'm Jordan, a junior front-end developer, who does a lot of things.</span>
</div>
<div className="description-caption">
<span>Prepare you to encounter various types of projects... but it's ok, just explore !</span>
</div>
<div className="button-container">
<a href="#works"><button>Scroll down</button></a>
</div>
</div>
<div className="side-content">
<span
className="txt-rotate"
data-period="1100"
data-rotate='[ "Web development", "Video editing", "Motion design", "Graphism", "Creativity" ]'></span><span>.</span>
</div>
<div className="side-text-portfolio">
<span>ポ<br />ー<br />ト<br />フ<br />ォ<br />リ<br />オ</span>
</div>
</div>
);
}
}
export default Main;
The script -
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
If you have any solutions for adding the script into my Component, or the properly reload it ... thanks by advance
javascript reactjs components
add a comment |
I'm working on a React component and I found a specific javascript code that modify the content of my html page.
The problem is that I don't know how to merge this script into my component. I know I can call it with an "import" statement but the script works with a "window.onload" function that will be called only one time, but my component is mounted several times and the script won't work anymore
The Component -
import React, { Component } from 'react';
import textRotation from '../../scripts/textRotation';
import './Main.scss';
class Main extends Component {
constructor(props) {
super(props);
this.title = props.title;
this.imgSrc = props.imgSrc;
}
render() {
return (
<div className="Main">
<div className="main-content">
<div className="presentation-caption">
<span>Hello, I'm Jordan, a junior front-end developer, who does a lot of things.</span>
</div>
<div className="description-caption">
<span>Prepare you to encounter various types of projects... but it's ok, just explore !</span>
</div>
<div className="button-container">
<a href="#works"><button>Scroll down</button></a>
</div>
</div>
<div className="side-content">
<span
className="txt-rotate"
data-period="1100"
data-rotate='[ "Web development", "Video editing", "Motion design", "Graphism", "Creativity" ]'></span><span>.</span>
</div>
<div className="side-text-portfolio">
<span>ポ<br />ー<br />ト<br />フ<br />ォ<br />リ<br />オ</span>
</div>
</div>
);
}
}
export default Main;
The script -
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
If you have any solutions for adding the script into my Component, or the properly reload it ... thanks by advance
javascript reactjs components
add a comment |
I'm working on a React component and I found a specific javascript code that modify the content of my html page.
The problem is that I don't know how to merge this script into my component. I know I can call it with an "import" statement but the script works with a "window.onload" function that will be called only one time, but my component is mounted several times and the script won't work anymore
The Component -
import React, { Component } from 'react';
import textRotation from '../../scripts/textRotation';
import './Main.scss';
class Main extends Component {
constructor(props) {
super(props);
this.title = props.title;
this.imgSrc = props.imgSrc;
}
render() {
return (
<div className="Main">
<div className="main-content">
<div className="presentation-caption">
<span>Hello, I'm Jordan, a junior front-end developer, who does a lot of things.</span>
</div>
<div className="description-caption">
<span>Prepare you to encounter various types of projects... but it's ok, just explore !</span>
</div>
<div className="button-container">
<a href="#works"><button>Scroll down</button></a>
</div>
</div>
<div className="side-content">
<span
className="txt-rotate"
data-period="1100"
data-rotate='[ "Web development", "Video editing", "Motion design", "Graphism", "Creativity" ]'></span><span>.</span>
</div>
<div className="side-text-portfolio">
<span>ポ<br />ー<br />ト<br />フ<br />ォ<br />リ<br />オ</span>
</div>
</div>
);
}
}
export default Main;
The script -
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
If you have any solutions for adding the script into my Component, or the properly reload it ... thanks by advance
javascript reactjs components
I'm working on a React component and I found a specific javascript code that modify the content of my html page.
The problem is that I don't know how to merge this script into my component. I know I can call it with an "import" statement but the script works with a "window.onload" function that will be called only one time, but my component is mounted several times and the script won't work anymore
The Component -
import React, { Component } from 'react';
import textRotation from '../../scripts/textRotation';
import './Main.scss';
class Main extends Component {
constructor(props) {
super(props);
this.title = props.title;
this.imgSrc = props.imgSrc;
}
render() {
return (
<div className="Main">
<div className="main-content">
<div className="presentation-caption">
<span>Hello, I'm Jordan, a junior front-end developer, who does a lot of things.</span>
</div>
<div className="description-caption">
<span>Prepare you to encounter various types of projects... but it's ok, just explore !</span>
</div>
<div className="button-container">
<a href="#works"><button>Scroll down</button></a>
</div>
</div>
<div className="side-content">
<span
className="txt-rotate"
data-period="1100"
data-rotate='[ "Web development", "Video editing", "Motion design", "Graphism", "Creativity" ]'></span><span>.</span>
</div>
<div className="side-text-portfolio">
<span>ポ<br />ー<br />ト<br />フ<br />ォ<br />リ<br />オ</span>
</div>
</div>
);
}
}
export default Main;
The script -
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
If you have any solutions for adding the script into my Component, or the properly reload it ... thanks by advance
javascript reactjs components
javascript reactjs components
asked Nov 20 at 23:37
JoVsn
31
31
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Change the script to this:
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
loadCall = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
const loadMyScript = () => window.addEventListener('load', () => loadCall());
export default loadMyScript;
Then import loadMyScript
and call loadMyScript()
from the componentDidMount()
function within your component.
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
add a comment |
If you are able to change the code in the script, you can change it to be callable instead of firing on load, i.e. give the function a name. And then you can call that function in the componentDidMount hook of your component.
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403233%2fhow-to-use-javascript-in-react-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change the script to this:
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
loadCall = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
const loadMyScript = () => window.addEventListener('load', () => loadCall());
export default loadMyScript;
Then import loadMyScript
and call loadMyScript()
from the componentDidMount()
function within your component.
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
add a comment |
Change the script to this:
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
loadCall = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
const loadMyScript = () => window.addEventListener('load', () => loadCall());
export default loadMyScript;
Then import loadMyScript
and call loadMyScript()
from the componentDidMount()
function within your component.
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
add a comment |
Change the script to this:
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
loadCall = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
const loadMyScript = () => window.addEventListener('load', () => loadCall());
export default loadMyScript;
Then import loadMyScript
and call loadMyScript()
from the componentDidMount()
function within your component.
Change the script to this:
var TxtRotate = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtRotate.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 300 - Math.random() * 100;
if (this.isDeleting) { delta /= 2; }
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
loadCall = function () {
var elements = document.getElementsByClassName('txt-rotate');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-rotate');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtRotate(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #725070 }";
document.body.appendChild(css);
};
const loadMyScript = () => window.addEventListener('load', () => loadCall());
export default loadMyScript;
Then import loadMyScript
and call loadMyScript()
from the componentDidMount()
function within your component.
answered Nov 21 at 0:48
Caleb Lucas
665
665
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
add a comment |
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
Thanks for the help, I applied the code you gave me plus a modification given in the comment left by @tenor528 : I call the function "loadCall" each time in the componentDidMount function and this now works
– JoVsn
Nov 21 at 21:02
add a comment |
If you are able to change the code in the script, you can change it to be callable instead of firing on load, i.e. give the function a name. And then you can call that function in the componentDidMount hook of your component.
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
add a comment |
If you are able to change the code in the script, you can change it to be callable instead of firing on load, i.e. give the function a name. And then you can call that function in the componentDidMount hook of your component.
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
add a comment |
If you are able to change the code in the script, you can change it to be callable instead of firing on load, i.e. give the function a name. And then you can call that function in the componentDidMount hook of your component.
If you are able to change the code in the script, you can change it to be callable instead of firing on load, i.e. give the function a name. And then you can call that function in the componentDidMount hook of your component.
answered Nov 20 at 23:50
tenor528
827917
827917
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
add a comment |
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
This works well, thank you very much !
– JoVsn
Nov 21 at 21:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403233%2fhow-to-use-javascript-in-react-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown