getCitiesOptions = () => {
const country = +this.state.country;
return Object
.entries(cities)
.filter(n => n[1].country === country)
.map(([ id, city ]) => <option key={id} value={id}>{city.name}</option>);
}
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>}
...
);
}
<div id="app"></div>
function App() {
const [ dark, setDark ] = React.useState(null);
const updateDark = e => setDark(e.type === 'mouseover' ? e.currentTarget.id : null);
return (
<React.Fragment>
{[ 'left', 'right' ].map(n => (
<div
id={n}
key={n}
onMouseOver={updateDark}
onMouseLeave={updateDark}
className={dark && dark !== n ? 'dark' : ''}
></div>
))}
</React.Fragment>
);
}
ReactDOM.render(<App />, document.getElementById('app'));
if (novyna.lenght) {
в процессе экспериментов было установлено, что если написать в условии вообще какую-либо фигню, типа if(novyna.lenght=55), то новости выводятся как ни в чем не бывало
class News extends React.Component {
const News = ({ news }) =>
<div className="news">
{Array.isArray(news) && news.length
? news.map(n => (
<div key={n.id}>
<p className="news__author">{n.author}:</p>
<p className="news__text">{n.text}</p>
<hr/>
</div>
))
: <p>Нет</p>}
<strong>Всего новостей: {news.length}</strong>
</div>;
почему вот такой код не работает
onLoad={(inst)=>{return inst.events.add('click', clickOnMap)}}
instanceRef={inst => inst.events.add('click', clickOnMap)}
onClick={clickOnMap}
const citiesListNames = citiesList.map( item => { return item.name } )
приложение зависает от такого колличества данных
class App extends React.Component {
state = {
items: [
{ id: 69, text: 'hello, world!!' },
{ id: 187, text: 'fuck the world' },
{ id: 666, text: 'fuck everything' },
],
active: null,
}
onClick = e => {
this.setState({
active: +e.target.dataset.index,
});
}
render() {
const { items, active } = this.state;
return (
<div>
{items.map((n, i) => (
<div
key={n.id}
data-index={i}
className={i === active ? 'active' : ''}
onClick={this.onClick}
>{n.text}</div>
))}
</div>
);
}
}
const Header = ({ Top }) => (
<div className="navHeader">
<Top />
</div>
);
...
<Header Top={Top} />
class TabContent extends React.Component {
render() {
const { title, content } = this.props;
return (
<div className="tabcontent">
<h3>{title}</h3>
<p>{content}</p>
</div>
);
}
}
class Tabs extends React.Component {
state = {
active: null,
}
openTab = e => this.setState({
active: +e.target.dataset.index,
});
render() {
const { items } = this.props;
const { active } = this.state;
return (
<div>
<div className="tab">
{items.map((n, i) => (
<button
className={`tablinks ${i === active ? 'active' : ''}`}
onClick={this.openTab}
data-index={i}
>{n.title}</button>
))}
</div>
{items[active] && <TabContent {...items[active]} />}
</div>
);
}
}
const Modal = (props) => {
const onClick = e => {
if (e.target.classList.contains('close') || !e.target.closest('.modal-content')) {
props.close();
}
}
return (
<div className="modal" onClick={onClick}>
<div className="modal-content">
<span className="close">×</span>
{props.children}
</div>
</div>
);
};
const App = () => {
const [ opened, setOpened ] = React.useState(false);
const open = () => setOpened(true);
const close = () => setOpened(false);
return (
<div>
<h2>Modal Example</h2>
<button onClick={open}>Open Modal</button>
{opened && <Modal close={close}>hello, world!!</Modal>}
</div>
);
}
activeProjects.map((project, i) => { <div key={i} className="focus-projects">
render() {
const activeProjects = this.props.projects.filter(n => n.ProjectStatus === 'ACTIVE');
...