Created
March 12, 2019 08:03
-
-
Save dra1n/65b24ea142c0d4730b02af5218dca6ef to your computer and use it in GitHub Desktop.
React code review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { PureComponent } from 'react' | |
| import PropTypes from 'prop-types' | |
| import { connect } from 'react-redux' | |
| class Parent extends PureComponent { | |
| handleUserClick(user) { | |
| alert(`Hello I am ${user.name}`) | |
| } | |
| render() { return null } | |
| } | |
| class Child extends Parent { | |
| static propTypes = { | |
| handleUserClick: PropTypes.func.isRequired | |
| } | |
| constructor(props) { | |
| this.state = { | |
| users: props.users, | |
| flag: false | |
| } | |
| } | |
| componentWillMount() { | |
| const { filterClientInput } = this.refs | |
| const { users } = this.state | |
| window.addEventListener('scroll', (e)=>console.log(e.target)) | |
| filterClientInput.focus() | |
| if (users.length > 0) { | |
| this.setState(Object.assign({ flag: true }, this.state)) | |
| } | |
| } | |
| handleChangeSearchInput(e) { | |
| console.log(e.target.value) | |
| } | |
| render() { | |
| const { handleUserClick } = this | |
| const { users } = this.state | |
| return ( | |
| { | |
| flag && | |
| <div className="page-wrapper"> | |
| <input | |
| name={'search-input'} | |
| ref="filterClientInput" | |
| onChange={this.handleChangeSearchInput(e)} | |
| /> | |
| <div> | |
| { | |
| users.map(user => | |
| <div | |
| className="user-wrapper" | |
| onClick={handleUserClick(user)} | |
| > | |
| <div className="user-name"> | |
| {user.name} | |
| </div> | |
| <div className="user-photo"> | |
| {user.photo} | |
| </div> | |
| </div> | |
| ) | |
| } | |
| </div> | |
| </div> | |
| } | |
| ) | |
| } | |
| } | |
| const mapStateToProps = state => ({ users: state.users }) | |
| export default connect()(Child) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment