0

Can you give me a hand with this expression . Basically what i am trying to say is If props.row.registered is true set disabled to be true or if is props.row.registered is undefined set it to false.

<Button
     disabled={!props.row.registered ? true : !props.row.registered === undefined ? false : true}
    ...
    />

2 Answers 2

2

Your ternary operator is basically doing this:

if(props.row.registered === true) {
  return true;
else {
  return false;
}

which can be simplified to:

return props.row.registered;

So for your conditions it would be:

props.row.registered || props.row.registered !== undefined

(based on your statement since your code it's setting disabled to true if props.row.registered is false, which is the opposite of your statement)

Sign up to request clarification or add additional context in comments.

3 Comments

!props.row.registered === undefined seems fishy :) did you want to write && props.row.registered !== undefined? In general, undefined is falsy though.
basically the idea is when i get a boolean value from props.row.registered to determinate the disabled , but when i dont have acess to this value in my case undefined to return the button to be disabled=false
disabled={!props.row.registered && props.row.registered !== undefined} this have done the job thanks mate
1

Your boolean can have 4 values: false, true, undefined and null.

disabled={props.row.registered}

should be enough for your use case because undefined and null are both falsy.

2 Comments

yeah but i want when i have a undefined value the disabled to be setted to false. In my case when i write disabled={!props.row.registered} is working fine but when i switch to the next page for some reason the rest of the buttons when they dont have this registered boolean value or value of undefined they are also disabled .
@PandaMastr Then your error is probably somewhere else. undefined won't make your button disabled. Note there is no ! in mine since you said that you want registered === true to make the button disabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.