display: flex
и вешайте ему класс, который будет переопределять order
у дочерних элементов. const letters = {
'а': 'a',
'б': 'b',
'в': 'v',
...
};
state = {
value: '',
translitValue: '',
}
onChange = ({ target: { value } }) => {
this.setState({
value,
translitValue: value.toLowerCase().split('').map(n => letters[n] || n).join(''),
});
}
<input value={this.state.value} onChange={this.onChange} />
<input value={this.state.translitValue} readOnly />
const items = [
{ title: 'London', content: 'London is the capital city of England.' },
{ title: 'Paris', content: 'Paris is the capital of France.' },
{ title: 'Tokyo', content: 'Tokyo is the capital of Japan.' },
];
const TabContent = ({ title, content }) => (
<div className="tabcontent">
<h3>{title}</h3>
<p>{content}</p>
</div>
);
function Tabs({ items }) {
const [ active, setActive ] = React.useState(null);
const openTab = e => setActive(+e.target.dataset.index);
return (
<div>
<div className="tab">
{items.map((n, i) => (
<button
className={`tablinks ${i === active ? 'active' : ''}`}
onClick={openTab}
data-index={i}
>{n.title}</button>
))}
</div>
{items[active] && <TabContent {...items[active]} />}
</div>
);
}
this.setState({
async componentDidMount() {
for (const url of urlList) {
const
dataAPI = [ ...this.state.dataAPI, await servicesAPI.getResourse(url) ],
loaded = dataAPI.length === urlList.length;
await new Promise(r => this.setState({ dataAPI, loaded }, r));
}
}
const items = [
{ id: ..., title: '...', img: '...' },
{ id: ..., title: '...', img: '...' },
...
];
function Slider({ items }) {
const [ active, setActive ] = React.useState(0);
const { length, [active]: slide } = items;
const next = e => setActive((active + +e.target.dataset.step + length) % length);
const goTo = e => setActive(+e.target.dataset.index);
return (
<div>
<div className="slideshow-container">
<div className="mySlides fade">
<div className="numbertext">{active + 1} / {length}</div>
<img src={slide.img} />
<div className="text">{slide.title}</div>
</div>
<a className="prev" onClick={next} data-step={-1}>❮</a>
<a className="next" onClick={next} data-step={+1}>❯</a>
</div>
<div className="dots">
{items.map((n, i) => (
<span
key={n.id}
className={`dot ${i === active ? 'active' : ''}`}
onClick={goTo}
data-index={i}
></span>
))}
</div>
</div>
);
}
function App() {
const [ count, setCount ] = useState(3);
const updateCount = ({ target: { dataset: { change } } }) =>
setCount(Math.max(0, count + +change));
const refs = useRef([]);
const logRefs = () => console.log(refs.current);
useEffect(() => {
refs.current.length = count;
}, [ count ]);
return (
<div>
<button onClick={updateCount} data-change={-1}>-</button>
{count}
<button onClick={updateCount} data-change={+1}>+</button>
<button onClick={logRefs}>log refs</button>
{Array.from({ length: count }, (n, i) => (
<div ref={el => refs.current[i] = el}>
{Math.random() * 1000 | 0}
</div>
))}
</div>
);
}
this.setState({
productToCart: {
...this.state.productToCart,
color,
},
});
{
title: 'Статус',
key: 'check',
dataIndex: 'check',
render: status => status ? 'На работе' : 'Отсутствует',
},
const ScrollButton = props => {
const onClick = () => window.scrollTo({
top: props.scrollTo,
behavior: 'smooth',
});
return (
<div className="down" style={{ top: `${props.top}px` }}>
Scroll to {props.scrollTo}
<button onClick={onClick}>❯</button>
</div>
);
};
const App = () => (
<div className="container">
<ScrollButton scrollTo={500} top={50} />
<ScrollButton scrollTo={1000} top={100} />
<ScrollButton scrollTo={2000} top={200} />
</div>
);
.down {
position: fixed;
}
появляется ошибка в консоли <...> Functions are not valid as a React child.
{this.countPrice}
. А надо {this.countPrice()}
. Ну или сделайте countPrice геттером.countPrice = () => {
return this.state.productsList.reduce((acc, n) => acc + n.price, 0);
}