Reading 20 Props and State - morgan-401-advanced-javascript/seattle-javascript-401n14 GitHub Wiki

Read

setState explained link

  • React components can, and often do, have state. State can be anything, but think of things like whether a user is logged in or not and displaying the correct username based on which account is active. Or an array of blog posts. Or if a modal is open or not and which tab within it is active.

  • React components with state render UI based on that state. When the state of components changes, so does the component UI.

  • That makes understanding when and how to change the state of your component important. At the end of this tutorial, you should know how setState works, and be able to avoid common pitfalls that many of us hit when when learning React.

functional vs class components link

Functional vs Class

  • The most obvious one difference is the syntax. A functional component is just a plain JavaScript function which accepts props as an argument and returns a React element.

  • A class component requires you to extend from React.Component and create a render function which returns a React element.

  • Because a functional component is just a plain JavaScript function, you cannot use setState() in your component. That’s the reason why they also get called functional stateless components. So everytime you see a functional component you can be sure that this particular component doesn’t have its own state.

handling eventslink

  • React events are named using camelCase, rather than lowercase.
  • With JSX you pass a function as the event handler, rather than a string.

passing additional parameter:

<button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button> <button onClick={this.deleteRow.bind(this, id)}>Delete Row</button>

forms link

Skim

state and lifecycle link

Watch

Bookmark

components and props link

⚠️ **GitHub.com Fallback** ⚠️