class App extends React.Component {
state = {
category: 'business',
items: [],
};
componentDidMount() {
this.fetchData();
}
fetchData() {
axios.get('https://newsapi.org/v2/top-headlines?country=us&category='+this.state.category)
.then(res => {
this.setState({ items: res.data.articles });
});
}
changeCategory = () => {
this.setState(
{ category: 'entertainment' },
this.fetchData,
);
};
render() {
return (
<div className='wrapper'>
<button onClick={this.changeCategory}>CLICK</button>
</div>
);
}
}
import libraryName from 'libraryName';
libraryName.someMethod();
import { someMethod } from 'libraryName';
someMethod();
Самому писать
<form>
<div class="form-group">
<label for="InputFile">File input</label>
<input type="file" id="InputFile" @change="onFileChange">
<p class="help-block">Upload image</p>
</div>
</form>
onFileChange (e) {
let file = e.target.files[0] || e.dataTransfer.files[0]
let formData = new FormData()
formData.append('image', file)
this.$http.post('upload/', formData)
.then(response => {
console.log(response)
}, error => {
console.log(error)
})
}
.split('').reverse().join('')
и проверять только начало /^\d{4,}_/
var re = new RegExp('^https?://(\\w+\\.)?avito\\.ru/([^/]+/)+([a-z_]+(?!_\\d{4,}))$');
var t1 = 'https://www.avito.ru/moskva/odezhda_obuv_aksessuary/magazin_pizham_kigurumi_na_lubyanke_56545';
var t2 = 'https://www.avito.ru/moskva/kvartiry/snimu';
re.test(t1) // false
re.test(t2) // true
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class Example extends Component {
handler = () => {
this.props.history.push('/cources');
};
render() { /* ... */ }
}
export default withRouter(Example);
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Example extends Component {
render() {
return <Link to="/cources" />;
}
}
export default Example;
<Route
render = { props => logged ? <Product /> : <Redirect to='/' /> }
exact
path='/products/:id'
/>
return state["users"].entities.forEach(user => { if (user.email === state["auth"].user.email) { return user; } });
return state.users.entities.find(user => user.email === state.auth.user.email);