I have a function that getting val
as a parameter and I want to set this.props.val
as default value.
My current function:
foo(val = this.props.val) {
console.log(val);
}
I'm getting the follow lint error:
Must use destructuring props assignment (react/destructuring-assignment)
Is it possible to use props as a default value in a different way that will stand in the react/destructuring-assignment
rule?
Maybe there is some trick similar to the following?
foo({ val } = this.props) {
console.log(val);
}
In the example above:
foo(5);// val = undefined
foo({val:5});// val = 5
foo();//val = this.props.val
Expected result
foo(5);// val = 5
foo({val:5});// val = {val:5}
foo();//val = this.props.val
[ I can use
foo(val) {
const { val: valProps } = this.props;
const newVal = val || valProps;
console.log(newVal);
}
but I'm trying to find a cleaner way]