Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

react components managing state quiz - questions 5 & 6

I am entering what I am pretty sure are correct answers for the coding portion of this quiz but I keep failing the quiz based on the last two questions, the answers are pretty straight forward, I think there may be a glitch, can someone take a look and advise

I would recommend posting your code so others can take a look and help you out. Just remember to reference the Markdown Cheatsheet when posting a snippet of your code.

Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

Answer to question 5

class ControlledInput extends Component {
  state = {
    value: ' '
  };
  handleChange(e) {
    this.setState({ value: e.target.value });
  }
  render() {
    return (
      <input 
        type="text" 
        value={ this.state.value }   
        onchange={ this.handleChange }
      />
    );
  }
}
Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

answer to question 6

class Students extends Component {
  state = {
    students: [ // array of student objects ]
  };
  this.setState( prevState => ({
    students: [
       ...this.state.students,
      { // new student object }
    ]
  }));
  render() { ... }
}

2 Answers

Hi there Bryant, for question 5 Tanuki is absolutely correct, you just need to capitalize the 'C' in onChange. For question number 6, note that they are asking to bring the students in from the previous state, and that they have used the expanded form of the setState function that passes the prevState parameter to the function body. So, instead of using ...this.state.students, you would want to use ...prevState.students.

Hope this helps!

tanuki
tanuki
1,567 Points

Capital C in question 5.