Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

Difference between state and props?

0 votes
28 views
added Mar 11 in ES6 by LC Marshal Captain (20,510 points)
props & state both are JS objects. Props could get across component whereas state is managed within the component (only)

1 Response

0 votes
responded Mar 11 by LC Marshal Captain (20,510 points)

props example;

import React from 'react'

class PropComponent extends React.Component {
    render () {
        return (
            <div>
                <h3>{this.props.headerProp}</h3>
                <p>{this.props.contentProp}</p>
            </div>
        )
    }
}

PropComponent.defaultProps = {
    headerProp: 'Header prop here',
    contentProp: 'Content prop goes here'
}
export default PropComponent;

 

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...