Stateless Components From Stateful Components
Learn React programming patterns for mixing components with and without state.
StartKey Concepts
Review core concepts you need to learn to master this subject
Stateful and Stateless Components
React Programming Pattern
Changing Props and State
Passing State Change Functions as Props
Event Handlers and State in React
Using Stateless Updaters and Presenters
Stateful and Stateless Components
Stateful and Stateless Components
class Store extends React.Component {
constructor(props) {
super(props);
this.state = { sell: 'anything' };
}
render() {
return <h1>I'm selling {this.state.sell}.</h1>;
}
}
class Week extends React.Component {
render() {
return <h1>Today is {this.props.day}!</h1>;
}
}
In React, a stateful component is a component that holds some state. Stateless components, by contrast, have no state. Note that both types of components can use props.
In the example, there are two React components. The Store
component is stateful and the Week
component is stateless.
- 1Let’s learn our first programming pattern! In this lesson, we’ll take a look at a simple version of a programming pattern. The following lessons will expand upon that lesson, and by the end, we…
- 2Let’s make a stateful component pass its state to a stateless component. To make that happen, you need two component classes: a stateful class, and a stateless class.
- 3Great! You just made a stateful component class named Parent. Now, let’s make our stateless component class.
- 4A is supposed to pass its state to a . Before a can pass anything to a , you need to import Child into Parent.js.
- 5Great work! You just passed information from a stateful component to a stateless component. You will be doing a lot of that. You learned earlier that a component can change its state by c…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory