const links = [
{
label: 'Home',
path: '/',
},
{
label: 'About',
path: '/about',
},
{
label: 'Shop',
path: '/shop',
},
{
label: 'Home',
path: '/',
},
{
label: 'Contact',
path: '/contact',
},
];
return (
<Wrapper>
{links.map((link, i) => (
<Link key={i} to={link.path}>
{link.label}
</Link>
))}
</Wrapper>
);
this.state.href[0] // первый элемент массива
import { applyContainerQuery } from 'react-container-query';
import { Hello, Boy, Wrapper } from '../somePlace';
const myQuery = {
hasMinWidth: {
minWidth: 1024,
},
};
class MyComponent extends Component {
...
render() {
const {
containerQuery: { hasMinWidth },
} = this.props;
return (
<Wrapper>
{hasMinWidth ? <Hello /> : <Boy />}
</Wrapper>
);
}
}
export default applyContainerQuery(MyComponent, myQuery);
export default function(state = initialState, action) {
if (action.type === 'DIALOG_SELECTED') {
return state;
}
if (action.type === 'DIALOG_DELETE') {
const newState = [...state];
newState.shift();
return newState;
}
else {
return state;
}
}
const mapStateToProps = state => ({
dialogs: state.dialogs,
});
const mapDispatchToProps = {
selectDialog: actions.selectDialog,
deleteDialog: actions.deleteDialog,
};
export default connect(mapStateToProps, mapDispatchToProps)(Sidebar);
class Sidebar extends Component {
selectDialog = () => {
this.props.selectDialog();
};
deleteDialog = () => {
this.props.deleteDialog();
};
render() {
console.log('рендер сайдбара');
return (
<div className='sidebar'>
<div className='sidebar__content'>
<div className='sidebar__head'></div>
<SidebarChatGroup chatName='Общий'>
<button onClick={this.selectDialog}>Выбрать</button>
<button onClick={this.deleteDialog}>удалить</button>
</SidebarChatGroup>
</div>
<div className='sidebar__bg'></div>
</div>
)
}
}
const circle_1 = [7, 2, 3, 5, 16, 50, 25, 40],
circle_2 = [2, 5, 10, 30, 25, 3, 10, 25],
circle_3 = [25, 10, 2, 10, 5, 2, 10, 5],
circle_4 = [7, 2, 3, 20, 3, 7, 2, 5],
circle_5 = [2, 20, 1, 7, 25, 1, 25],
circle_6 = [3];
function findSum(value, arrays, i = 0) {
for (let j = 0; j < arrays[i].length; j++) {
const el = arrays[i][j];
if (i < arrays.length - 1) {
const result = findSum(value - el, arrays, i + 1);
if (result !== null) {
return [el, ...result];
}
} else if (el === value) {
return [el];
}
}
return null;
}
console.log('result', findSum(136, [
circle_1,
circle_2,
circle_3,
circle_4,
circle_5,
circle_6
]));
// => result [50, 30, 25, 3, 25, 3]
class FormWidget extends Component {
state={
isFormVisible: false,
};
handleButtonClick = () => {
this.setState(prevState => ({
isFormVisible: !prevState.isFormVisible,
}));
}
render() {
const { isFormVisible } = this.state;
const buttonText = isFormVisible ? 'Hide form' : 'Show form';
return (
<Wrapper>
<Button onClick={this.handleButtonClick}>
{buttonText}
</Button>
<Form isVisible={isFormVisible} />
</Wrapper>
)
}
}
var foo = {
bar: 'bar value',
};
console.log(foo.bar);
// => bar value
console['log'](foo['bar']);
// => bar value
var action = 'addClass';
$('.some-selector')[action]('some-class');
$('.some-selector').addClass('some-class');
var key = 'name';
var obj = {
name: 'Tom',
age: 24,
};
console.log(obj[key]);
// => Tom
console.log(obj.name);
// => Tom
console.log(obj[key] === obj.name);
// => true
key = 'age';
console.log(obj[key]);
// => 24
var obj = {
'three words key': 'value',
};
console.log(obj['three words key']);
// => value
var leftMenu = document.querySelector(".left-menu");
var displayValue = window.getComputedStyle(leftMenu,null).getPropertyValue("display");
console.log(displayValue === 'none');
var someBtn = document.getElementById('all');
someBtn.onclick = function() {
myFunction(5);
}
function myFunction(a){
alert(a);
}
var someBtn = document.getElementById('all');
someBtn.onclick = function() {
alert(5);
}
var someBtn = document.getElementById('all');
someBtn.addEventListener('click', function() {
myFunction(5);
});
function myFunction(a){
alert(a);
}
const array = [{ name: 'John', age: 32}];
const element = { name: 'Sally', age: 25 };
const newArray = [ ...array, element ];
// => [{ name: 'John', age: 32}, { name: 'Sally', age: 25 }]
document.getElementById("myForm").reset();
$('#myForm').trigger("reset");
body: `Hey, ${userName}! You've been notified!`,
body: "Hey, " + userName + "! You've been notified!",
NaN !== NaN // true
isNaN(undefined); // true
isNaN({}); // true
isNaN('test'); // true
$('.f1').on('change', function(e) => {
var value = $(e.currentTarget).val();
})
$(document).find('.form-element').on('change', e => console.log($(e.currentTarget).val()));
const array = Array.prototype.slice.call(nodeList);
const array = Array.from(nodeList)
const array = [...nodeList];