Answer the question
In order to leave comments, you need to log in
How to read (decode) lines in this React code?
Hello! I am learning react.js. In addition to writing my own code, I try to study the code of other people that I come across on the Internet and on the forum. But not everything is clear, so I want to ask you how to correctly decrypt some lines of code, that is, not only what the indicated lines do, but also how they are decrypted. The code itself implements modal images.
Please help me comment on the lines I commented out by analogy with how I commented on line #1.
class App extends React.Component {
state = {
images: [
'https://pixel.nymag.com/imgs/daily/intelligencer/2018/08/24/24-donald-trump-2.w700.h700.jpg',
'https://bi.im-g.pl/im/15/a2/17/z24782357Q,Donald-Trump--prezydent-USA.jpg',
'https://mobilitynews.pl/wp-content/uploads/2018/05/trump.jpg',
],
openedImage: null,
}
open = e => {
this.setState({
openedImage: e.target.src,
});
}
close = () => {
this.setState({ openedImage: null, }); /* Строка №1: Устанавливаю метод setState обьекту state, а в качестве аргумента метода пишу свойство обьекта state- openedImage с значением null.*/
}
render() {
const { images, openedImage } = this.state;
return (
<div className="portfolio">
<div className="portfolio-container">
{images.map(n => ( // Строка №2
<div className="foto-container">
<img
className="foto-portfolio"
src={n} // Строка №3
onClick={this.open}
/>
</div>
))}
</div>
{openedImage && <div className="modal-portfolio"> // Строка №4
<span className="close" onClick={this.close}>×</span>
<img className="modal-content" src={openedImage} /> // Строка №5
</div>}
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question