Difference between state and props?

0 votes
366 views
added Mar 11, 2019 in ES6 by LC Marshal Captain (25,790 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, 2019 by LC Marshal Captain (25,790 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.
...