Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

javascript - How can I trigger an event on page load in React?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your question is limited in explanation.It would be good if you would have shared some more code.But I will answer as per my understanding of the question.

My understanding of question:You are getting some value from footer and based on that value you want to trigger some kind of event in your page.

So,this is how you should do it.

useEffect(()=>{
//Do some event after getting value
},[value which you get from footer]).

let me explain what i have written here. First read a bit out useEffect.that would help you here. Whatever value(just an example) you get from footer put it in a variable.Now use that variable in the useEffect depenedency array.

A basic example.

function demo(){
let a;
React.useEffect(()=>{
//do yourlogic here;
},[a]);
a=10;

in the above example whenever the value of a changes the useEffect will be triggered.

You can try similar approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...