Manage State Locally First - Console State Issue

Why can’t I console.log the state.input in submitMessage()?
This is just straight up React, so can’t I just reference the property without using getState()?

Your code so far

class DisplayMessages extends React.Component {
  constructor(props) {
    this.state = {
      input: '',
      messages: []
  // add handleChange() and submitMessage() methods here
  handleChange(e) {
      input :
    // console.log(this.state.input); // works


  submitMessage() {
      messages : [...messages, input]
    this.getState((curState) => {

  render() {
    return (
        <h2>Type in a new Message:</h2>
        { /* render an input, button, and ul here */ }
          <input onChange={this.handleChange.bind(this)} />
          <button onClick={this.submitMessage}>Submit</button>
        { /* change code above this line */ }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:

There is no built-in function named getState that I am aware of.

You can reference the state’s input property by using this.state.input

1 Like

getState is a redux thing, that is a method on the redux store that retrieves the current state (something you rarely need, since reducers also get the current state). As @RandellDawson mentioned, there’s no such method on react components – just grab the state directly from this.state.