Conversation
src/App.js
Outdated
|
|
||
| handleSelect(value) { | ||
| let result = this.state.data.contacts.filter( function (obj) { | ||
| return obj._id == value; |
There was a problem hiding this comment.
Careful using the double == operator, it does some strange parsing that can lead some hard to track down errors. In general I think it's better to use the triple equals just for simplicity.
Here's a little blurb:
"double equals will perform a type conversion when comparing >two things; triple equals will do the same comparison without type >conversion (by simply always returning false if the types differ);
There was a problem hiding this comment.
Great comment. I would follow the rule to NEVER use the == operator. I thought I added the eslint rule for that...
|
|
||
| this.name = this.props.name.toLowerCase(); | ||
| this.searchValue = this.props.searchValue.toLowerCase().trim(); | ||
| this.pos = this.name.search(this.searchValue); |
| @@ -0,0 +1,12 @@ | |||
| import React from 'react'; | |||
There was a problem hiding this comment.
Good thinking breaking out the text into it's own component
src/components/button.js
Outdated
| } | ||
|
|
||
| Button.propTypes = { | ||
| resetSelection: React.PropTypes.isfunc, |
There was a problem hiding this comment.
Close! I made a similar error. For a function proptype, the syntax is React.PropTypes.func , generally you'd also want to make it required which looks like this: React.PropTypes.func.isRequired
src/components/contact-list.js
Outdated
| <ul className="contact-list"> | ||
| {contacts.map((contact,i) => { | ||
| return ( | ||
| <Contact {...contact} handleSelect={this.props.handleSelect} key={i} searchValue={this.props.searchValue} /> |
There was a problem hiding this comment.
Nice use of the spread operator, I'm gonna refactor my code to do this.
ivome
left a comment
There was a problem hiding this comment.
Great job on the implementation! There are a few things in your code that eslint should tell you about.
src/App.js
Outdated
| import Button from './components/button.js'; | ||
| import axios from 'axios'; | ||
|
|
||
| const data = { |
There was a problem hiding this comment.
I wouldn't recommend using local variables and mix it with state. This will create a whole bunch of problems when you have multiple instances of the same component on your page. They use the same data and the values get mutated in different locations. Better exclusively keep that in the component state.
src/App.js
Outdated
| componentDidMount() { | ||
| axios.get('http://localhost:4000/contacts') | ||
| .then(resp => { | ||
| data.contacts = resp.data; |
There was a problem hiding this comment.
Mutating the data object is dangerous, since in your implementation all instances of the Component share the same variable. Also see comment above. Just use state for that and remove the local variable above.
| this.state.data.contacts.map((obj) => { | ||
| obj.isSelected = false; | ||
| }) | ||
| ); |
| this.setState( | ||
| this.state.data.contacts.map((obj) => { | ||
| obj.isSelected = false; | ||
| }) |
There was a problem hiding this comment.
setState always takes an Object as an argument. You are passing an array (the return value of the map function). This only works, because you are mutating the state directly through obj.isSelected. Mutation of the state should not be used at all in react. If you want to change something, you have to clone the objects.
You are making this harder than it is because you are storing everything in a data object inside of state. Better keep the state object flat and store everything on it directly.
src/App.js
Outdated
|
|
||
| handleSelect(value) { | ||
| let result = this.state.data.contacts.filter( function (obj) { | ||
| return obj._id == value; |
There was a problem hiding this comment.
Great comment. I would follow the rule to NEVER use the == operator. I thought I added the eslint rule for that...
src/components/contact-list.js
Outdated
| data: React.PropTypes.array, | ||
| name: React.PropTypes.string, | ||
| occupation: React.PropTypes.string, | ||
| handleSelect: React.PropTypes.isfunc |
There was a problem hiding this comment.
Proptype should be PropTypes.func, as mentioned above. Name for functions are usually called onSomeAction.
| import React from 'react'; | ||
| import Text from './text.js'; | ||
|
|
||
| const divStyle = { |
There was a problem hiding this comment.
Always try to use descriptive variable names
src/components/contact.js
Outdated
| <Text divStyle={divStyle} text={this.text2()} /> | ||
| <Text divStyle={divStyle2} text={this.text3()} /> | ||
| </span> | ||
| </h2> |
| @@ -0,0 +1,20 @@ | |||
| import React from 'react'; | |||
There was a problem hiding this comment.
File names should have the same name as the component name.
This could also be turned into a functional component.
src/components/text.js
Outdated
| @@ -0,0 +1,12 @@ | |||
| import React from 'react'; | |||
|
|
|||
| export default class Text extends React.Component { | |||
There was a problem hiding this comment.
Use functional components for only rendering things.
…and POST requests.
ivome
left a comment
There was a problem hiding this comment.
Great job! Keep up the good work!
| this.setState({ | ||
| selected: newSelection | ||
| } | ||
| ); |
| this.setState({ | ||
| picture: event.target.value | ||
| }); | ||
| } |
There was a problem hiding this comment.
Did you see the extension in the curriculum for how to write the handler logic in one function?
| this.state.contacts.map((obj) => { | ||
| obj.isSelected = false; | ||
| }) | ||
| ); |
No description provided.