The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Manage React Component State with Lifecycle Methods

Manage React Component State with Lifecycle Methods

1:58
The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson you will learn some simple uses for these hooks and how we can interact with state.
Watch this lesson now
Avatar
egghead.io

The previous lesson introduced the React component lifecycle mounting and unmounting. In this lesson you will learn some simple uses for these hooks.

Avatar
Christopher

I thought props were suppose to be readonly.

Why are you using setProps here instead of setState?

In reply to egghead.io
Avatar
Joseph

While using setProps may be considered an anti-pattern when allowing children components to update their own props in this case we have a single component for our entire app where using setProps or setState are both perfectly acceptable methods for triggering a render. The use of setProps here was actually added in the previous video merely to illustrate it's existence and usage.

In reply to Christopher
Avatar
Yu-Shih

Why do you store btnStyle directly on the object, instead of on the state?

Avatar
Fareez

Hi,
are these code examples supposed to be working with the latest version of react? none of the code samples are working for me.

Avatar
Faria

It's working for me, using react 0.13.2. Here is a working example of the above code:
http://jsfiddle.net/faria/d0sycoxv/1/

In reply to Fareez
Avatar
Brad

getting an error saying 'component's children should no be mutated'. in button...

Avatar

I really like the lessons, everything is becoming clear now.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?