Documenting my learning journey of Namaste React Live Course conducted by Akshay Saini
- Created About page as Class-based component.
-
Created two class-based child components (Profile & Blog) inside parent (About) Component
-
Brownie points : Created two more grandchildren components, one with Profile as parent (Social Component) and another with Blog as parent. I created grandchildren components to see how lifecycle methods works for nested components. For
Social Component
, I am not passing any props, whereas forRepo Component
I am passing state of its parent (Blog)repo
as props. Repo component shows a repository card for each of the repository in therepoList
state variable of Blog.
- props
name
is passed from parent to child component
About ----->(name as props) -----> Profile
About ----->(name as props) -----> Blog
Blog ------> (repo as props where repo is an object of Blog's state variable) -----> Repo
- In All Components, constructor are created. Props are passed to its parent component through super(props) and if any state is needed for a component, it is created in constructor.
- In Profile Component, State variable
userInfo
is created insideconstructor
- In Blog Component, State variables
blog
andrepoList
are created insideconstructor
- In Profile Component - After fetching the data from API, the state of
userInfo
is updated usingthis.setState()
- In Blog Component - After fetching the data from API, the state of both the states
blog
andrepoList
are updated usingthis.setState()
- There are two states for Blog Components -
blog
&repoList
, updating the state can happen separately in two this.setState() or together in the same this.setState(). I have updated both states together in the same this.setState()
- In all the components, console.log() statements are written in each lifecycle methods like
componentDidMount
,componentDidUpdate
,componentWillUnmount
along with constructor & render methods.
Component Hierarchy
About
- Profile
- Social
- Blog
- Repo
Order of their execution for the above nested component hierarchy is as follows :
About - constructor
About - render
Profile - constructor
Profile - render
Social - constructor
Social - render
Blog - costructor
Blog - render
Social - componentDidMount
Profile - componentDidMount
Blog - componentDidMount
Profile - render
Social - render
Social - componentDidUpdate
Profile - componentDidUpdate
Blog - render
(Repo - constructor
Repo - render ) - Repeat this for each repository (currently 10 times) (Important to note that Repo component is created only after Blog mounted because it is dependent on state variable of blog which is passed as props but this was not the scenario with Social-Profile relationship because it has no state passed as props)
Repo - componentDidMount - Repeat this for each repository (currently 10 times)
Blog - componentDidUpdate
About - componentWillUnmount
Profile - componentWillUnmount
Social - componentWillUnmount
Blog - componentWillUnmount
Repo - componentWillUnmount (10 times)