GroceriStar / react-only-intern-17

GNU General Public License v3.0
0 stars 0 forks source link

Master React, Quick Code tutorial. Part 7 #8

Open atherdon opened 6 years ago

atherdon commented 6 years ago

https://medium.com/quick-code/lets-learn-react-chapter-7-component-life-cycle-6aaa815747db

Expected result

Test

chefigueroa-rodriguez commented 6 years ago

Learned about the component life cycle, which are a series of actions which are executed:

  1. before component is displayed - componentWillMount()
  2. after component is displayed - componentDidMount()
  3. before component is updated - usecomponentWillUpdate()
  4. and after component is updated - componentDidUpdate()

Also learned how to dynamically render a message when the state is updated. By modifying our state:

state = { meal: '', meals: [], showAddMealMessage: false };

Adding our componentDidUpdate() function:

componentDidUpdate(prevProps, prevState) { if (prevState.meals.length < this.state.meals.length) { this.setState({showAddMealMessage: true}); setTimeout(() => this.setState({showAddMealMessage: false}), 1000); } }

And adding this line of code when we render:

{this.state.showAddMealMessage ?

New meal added

: null}

atherdon commented 6 years ago

assume you have a profile form, with default fields like email, username, image, description, etc. imagine how you'll create it and tell me how you'll handle a default form flow like updates, validation, etc. based on what you learn at this chapter.

atherdon commented 6 years ago

if you'll reply to my last comment, i think we can close this task and move to most interesting part of this course. Chapter 8 is really important for me, because it's introduce you to my projects, that we're currently working on