import ReactExport from "react-data-export";
const { ExcelFile } = ReactExport;
const { ExcelSheet } = ExcelFile;
function handleClickA() {
element.innerHTML += 'a';
}
function handleClickB() {
element.innerHTML += 'a';
}
a.addEventListener('click', hanldeClickA);
b.addEventListener('click', hanldeClickB);
function buildHandler(char) {
return function() {
element.innerHTML += char;
}
}
a.addEventListener('click', buildHandler(a.innerHTML));
b.addEventListener('click', buildHandler(b.innerHTML));
for (let key in keys) {
key.addEventListener('click', buildHandler(key.innerHTML);
}
Почему именно нужен return function() (не просто return)?
const Grid extends React.Component {
state = { itemsSize: 'sm' };
handleChangeSize = () => { /* some code */ };
render() {
const { itemSize } = this.state;
const { items } = this.props;
return (
<Wrapper>
<ControlPanel onChangeSize={this.handleChangeSize} />
{items.map(item => <Item key={item.id} size={this.state.itemSize} />)}
</Wrapper>
);
}
}
class ExampleComponent extends React.Component {
state = {
isReady: false,
};
hanldeOnLoad = () => {
this.setState({ isReady: true });
};
render() {
const { src } = this.props;
const { isReady } = this.state;
const className = isReady ? '' : 'some-class';
return (
<div className={className}>
<img onLoad={this.hanldeOnLoad} src={src} />
</div>
);
}
}
const hiddenSyle = props => props.hidden && css`
display: none;
`;
const disabledStyle = props => props.disabled && css`
pointer-events: none;
opacity: 0.3;
`;
const Input = styled.input`
${hiddenStyle}
${disabledStyle}
`;
function(done) {
setTimeout(function() {
done('result');
}, duration);
};
new Promise(resolve => {
setTimeout(resolve, duration, 'result');
});
function all(promises, done) {
const results = [];
let count = promises.length;
const checkDone = () => {
if (--count === 0) done(results);
};
promises.forEach((p, i) => {
p.then(x => results[i] = x).then(checkDone);
});
}
function promiseAll(promises) {
return new Promise(resolve => {
const results = [];
let count = promises.length;
const checkDone = () => {
if (--count === 0) resolve(results);
};
promises.forEach((p, i) => {
p.then(x => results[i] = x).then(checkDone);
});
});
}
async enableCropper() {
await this.preview({});
console.log('Все готово');
},
async preview(params) {
const { data } = await axios.post('/api/images/preview', params, {
responseType: 'blob',
});
await this.loadImage(data);
},
loadImage(src) {
return new Promise(resolve => {
const reader = new window.FileReader();
reader.readAsDataURL(src);
reader.onload = () => {
this.$refs.cropper.replace(reader.result);
console.log('Картинка готова');
resolve();
};
});
},