Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does const and props refer to in react-redux?

export default class customer  {

}

render(){
    const{
        handleSubmit,
        pristine,
        submitting
    } = this.props;
    return{
        <div>
        </div>
    }  
}

my react-redux code has something like this. can any one tell me why we are using const and this.props in the code

like image 405
LOKI Avatar asked Nov 16 '16 15:11

LOKI


1 Answers

can any one tell me why we are using "const"

const is another way to declare a variable. These variables disallow reassignment. const is generally a safer way to declare variables, depending on the developer's intent.

can any one tell me why we are using this.props in the code

That's an assignment/deconstructing shorthand. The syntax is something like this:

var {
  property
} = object;

What you're doing is creating local variables from the properties of the object. That code is identical to:

var property = object.property;

So in your code, you can think of

const {
    handleSubmit,
    pristine,
    submitting
} = this.props;

as simply

const handleSubmit = this.props.handleSubmit;
const pristine = this.props.pristine;
const submitting = this.props.submitting;
like image 124
Nick Zuber Avatar answered Oct 17 '22 23:10

Nick Zuber