Answer the question
In order to leave comments, you need to log in
How can this be implemented in react.js?
Hello.
I would like to ask more experienced programmers how to implement the below code in React? The problem is that I still have a fairly superficial understanding of React. And I really need the code in one of my projects.
The task is as follows:
There is a page, a few seconds after it is loaded, the "contact us" button appears, and after a few seconds a small window appears next to it with text from the consultant and his name.
Like this:
first:
and then:
<!--html-->
<div class="block-1">Блок 1</div>
<div class="block-2">Блок 2</div>
<!--js-->
const block1 = document.querySelector('.block-1');
const block2 = document.querySelector('.block-2');
setTimeout(function(){
block1.style.display = 'block';
setTimeout(function(){
block2.style.display = 'block';
},3000);
},3000);
<!--css-->
.block-1,.block-2 {
display: none;
}
Answer the question
In order to leave comments, you need to log in
state = {
block1: false,
block2: false,
}
componentDidMount() {
setTimeout(() => this.setState({ block1: true }), 3000);
setTimeout(() => this.setState({ block2: true }), 6000);
}
render() {
const { block1, block2 } = this.state;
return (
...
{block1 && <div class="block-1">Блок 1</div>}
{block2 && <div class="block-2">Блок 2</div>}
...
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question