Skip to content

Question 11 note #3

@engmagdy87

Description

@engmagdy87

Hi @sudheerj
in Q11, u wrote

Note: The only place you can directly assign to the state object is in constructor.

but u can remove the constructor from the component and access the state object

class Hello extends Component {
       state= {
           a:"hello",
           b:" react"
       }
render(){
    const {a,b} = this.state;
    return(
        <div>{a + b}</div>
    )
   }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions