- Каждый раз нужно импортировать текст-контент и брать значение по нужным ключам
i18nMessage('landing_header');
i18nPlural('comments_count', comments.size);
i18nWrapper('landing_caption', [<strong />]);
this.visibleCities = this.allCities.filter(city => this.defaultCitiesIds.includes(city.id))
.map(city => ({ ...city, check: false }));
this.visibleCities = this.allCities.reduce((result, city) => {
if (this.defaultCitiesIds.includes(city.id)) {
city.check = false;
result.push(city);
}
return result;
}, []);
// without compose
withLog(withRouter(connect(mapStateToProps)(withDropdown(props)(Component))));
// with compose
compose(
withLog,
withRouter,
connect(mapStateToProps),
withDropdown(props),
)(Component);
const foo = compose(...functions);
return возращает в скобках html код
render() {
return (
<h1 className="greeting">
Hello, world!
</h1>
);
}
render() {
return React.createElement(
'h1',
{ className: 'greeting' },
'Hello, world!'
);
}
{
$$typeof: Symbol(react.element),
key: null,
props: { className: "greeting", children: "Hello, world!" },
ref: null,
type: "h1",
_owner: null,
_store: { validated: false },
_self: null,
_source: null,
__proto__: Object,
}
React компилятор перед сборкой парсит данные в файлах компонентов...
...Я понимаю что реакт собирает все в ES2015...
или же это нормально для ES6
import * as React from 'react';
import styled from 'styled-components';
const Wrapper = styled.label`
position: relative;
display: inline-block;
width: 40px;
height: 24px;
`;
const Input: any = styled.input`
display: none;
`;
const Slider = styled.div`
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .2s;
border-radius: 34px;
&:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 1px;
bottom: 1px;
background-color: white;
transition: .2s;
border-radius: 50%;
}
${Input}:checked + & {
background-color: ${props => props.theme.someColor1};
}
${Input}:focus + & {
box-shadow: 0 0 1px ${props => props.theme.someColor2};
}
${Input}:checked + &:before {
transform: translateX(16px);
}
`;
interface Props = {
name?: string
checked?: boolean
onChange?: Function
innerRef?: Function
className?: string
}
const ToggleSwitch = ({ innerRef, checked, onChange, className, name }: Props) => {
return (
<Wrapper className={className}>
<Input
innerRef={innerRef}
checked={checked}
onChange={onChange}
name={name}
type="checkbox"
/>
<Slider />
</Wrapper>
);
}
import React from 'react';
export default Task;
constructor(props) {
super(props);
this.state = {
isOpened: false,
};
this.clickHandler = this.clickHandler.bind(this);
}
clickHandler = e => {
// your stuff
};
this.setState(prevState => ({
isOpened: !prevState.isOpened,
}));