Skip to content

James Kuhr Advanced 1#6

Open
jamesku wants to merge 5 commits intoAustinCodingAcademy:masterfrom
jamesku:master
Open

James Kuhr Advanced 1#6
jamesku wants to merge 5 commits intoAustinCodingAcademy:masterfrom
jamesku:master

Conversation

@jamesku
Copy link

@jamesku jamesku commented Jan 24, 2017

No description provided.

src/App.js Outdated

handleSelect(value) {
let result = this.state.data.contacts.filter( function (obj) {
return obj._id == value;
Copy link

@michaeb michaeb Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution for the highlighter!

@@ -0,0 +1,12 @@
import React from 'react';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking breaking out the text into it's own component

}

Button.propTypes = {
resetSelection: React.PropTypes.isfunc,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

<ul className="contact-list">
{contacts.map((contact,i) => {
return (
<Contact {...contact} handleSelect={this.props.handleSelect} key={i} searchValue={this.props.searchValue} />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the spread operator, I'm gonna refactor my code to do this.

Copy link
Contributor

@ivome ivome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
})
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

this.setState(
this.state.data.contacts.map((obj) => {
obj.isSelected = false;
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great comment. I would follow the rule to NEVER use the == operator. I thought I added the eslint rule for that...

data: React.PropTypes.array,
name: React.PropTypes.string,
occupation: React.PropTypes.string,
handleSelect: React.PropTypes.isfunc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always try to use descriptive variable names

<Text divStyle={divStyle} text={this.text2()} />
<Text divStyle={divStyle2} text={this.text3()} />
</span>
</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

@@ -0,0 +1,20 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File names should have the same name as the component name.
This could also be turned into a functional component.

@@ -0,0 +1,12 @@
import React from 'react';

export default class Text extends React.Component {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use functional components for only rendering things.

Copy link
Contributor

@ivome ivome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Keep up the good work!

this.setState({
selected: newSelection
}
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation... :-)

this.setState({
picture: event.target.value
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
})
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants