Answer the question
In order to leave comments, you need to log in
I can not understand what's the matter with react'om?
Good afternoon, I wanted to display a few and gives such a country error in the browser, nevertheless the compilation is successful
index.js
import React from 'react'
import {render} from 'react-dom'
import ArticleList from './ArticleList'
import {articles} from './fixtures'
render(<ArticleList articles = {articles} />, document.getElementById('container'))
import React from 'react'
import Article from './Article'
export default function ArticleList({articles}){
return(
<ul>
<li>Article article = {articles[0]}</li>
<li>Article article = {articles[1]}</li>
<li>Article article = {articles[2]}</li>
</ul>
)
}
import React, {Component} from 'react'
// *********************************** Более сложный синтакс с ООП подходом ************** //
export default class Article extends Component{ // Class Article
constructor(props){ // Инициализируем Конструктор
super(props)
this.state = { // Состояния объекта
isOpen: true // Задаем имя и состояние объекта
}
}
render(){ // метод render
const {article} = this.props // теперь props идет в this
const {isOpen} = this.state // Передаем в render константу isOpen
return (
<div>
<h1>{article.title}</h1>
<button onClick={this.toggleOpen}>
{isOpen ? 'close' : 'open'}
</button>
{this.getBody()}
</div>
)
}
getBody(){ // Выносим проверку в отдельные метод
if(!this.state.isOpen) return null // Если закрыто ничего не делаем
const {article} = this.props // Если открыто возврощаем section
return <section>{article.text}</section>
}
toggleOpen = () => { // Описание объкта toggleOpen
this.setState({
isOpen: !this.state.isOpen
})
}
}
Answer the question
In order to leave comments, you need to log in
Answering my own question
Note that the imported Component must be a Tag<li><Article article = {articles[0]}/></li>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question