LOKI LOKI - 20 days ago 8
React JSX Question

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

Answer

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;