import React, { Component } from 'react';
class Slider extends Component {
constructor(props){
super()
this.state=({
currentSlideImage : 0
})
}
handlePrevButton(){
let currentSlideImage = this.state.currentSlideImage;
this.setState({
currentSlideImage:currentSlideImage-1
})
}
handleNextButton(){
let currentSlideImage = this.state.currentSlideImage;
this.setState({
currentSlideImage:currentSlideImage+1
})
}
render() {
return (
<div className="container">
<button onClick={()=>this.handlePrevButton()}>Prev</button>
<img src={this.props.slides[this.state.currentSlideImage]} alt="slider-item"/>
<button onClick={()=>this.handleNextButton()}>Next</button>
</div>
);
}
}
export default Slider;
export const renderNotes = async(user , users) => async dispatch => {
let elements = await fire.database().ref('users/' + element + '/notes/'); // Вынес сюда присвоение
Object.keys(users).map(element => {
if (user === users[element].login) {
return dispatch({
type: RENDER_NOTES,
payload: elements
})
}
})
};
ереписать данное условие, если количество вариантов location более двух.
let CONTACTS = [
{
id:1,
name: 'Kamila Abcentova',
phoneNumber: '+79503124111',
image: 'https://i.pinimg.com/736x/63/57/fa/6357fa6703775b165e739a1c6a1d0899--berges-portrait-paintings.jpg'
},
{
id:2,
name: 'Denis Abramov',
phoneNumber: '+79506224211',
image: 'https://pbs.twimg.com/media/BvVsFVBCcAAT_Pt.jpg:large'
},
{
id:3,
name: 'Kristian Sendler',
phoneNumber: '+79236444211',
image: 'https://thairomances.com/userfiles/ProfilePhoto/14244/39093-full_size.jpg?v=3'
},
{
id:4,
name: 'Marat Kizombov',
phoneNumber: '+79321445511',
image: 'http://funstories.lol/wp-content/uploads/2016/07/2-121-768x768.jpg'
}
];
class Contact extends React.Component{
render(){
return <li className='contact'>
<img className='contact-image' src={this.props.image} width='60px' height='60px'/>
<div className='contact-info'>
<div className='contact-name'>{this.props.name}</div>
<div className='contact-phone'>{this.props.phoneNumber}</div>
</div>
</li>
}
}
class ContactList extends React.Component{
constructor(props){
super(props);
this.state={
input=""
}
this.handleSearch = this.handleSearch.bind(this);
}
handleSearch(el){
console.log(el.target.value)
this.setState({
input:el.target.value
})
}
render(){
return(
<div className='contacts'>
<input type='text' className='search-fields' onChange={this.handleSearch} value={this.state.input}/>
<div>{this.state.input}</div>
<ul className='contacts-list'>
{
CONTACTS.map(function(el){
return <Contact
key={el.id}
name={el.name}
phoneNumber={el.phoneNumber}
image={el.image}
/>;
})
}
</ul>
</div>
);
}
}
ReactDOM.render(
<ContactList/>,
document.getElementById('root')
)
const mapStateToProps = state => ({
usersListAuth: state.users.usersList,
usersListFriends: state.friends.userFriendList,
});
const mapDispatchToProps = dispatch => ({
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(UsersListContainer);
Passing:
class MyComponent extends React.Component {
constructor(props) {
super(props)
console.log(this.props)
// -> { icon: 'home', … }
}
}
Not passing:
class MyComponent extends React.Component {
constructor(props) {
super()
console.log(this.props)
// -> undefined
// Props parameter is still available
console.log(props)
// -> { icon: 'home', … }
}
render() {
// No difference outside constructor
console.log(this.props)
// -> { icon: 'home', … }
}
}