2

I'm working on small react app and my dropdowns looks like this:

<CustDropdown 
disabled={
      isPlayerLoaded ||
      this.state.players.length === 0 || 
      !this.state.players 
    }
/>

Issue here is I would like to get rid of this code after disabled. Is it possible to store it to somevariable which might be used here after disabled.

So disabled would look like disabled = isPlayerDisabled.

Thanks guys

Cheers

1 Answer 1

3

Before the return statement declare a const to hold the result of the logic operation. You can also use destructuring assignment to make your code more clean

const { players } = this.state
const disabled = isPlayerLoaded || players.length === 0 || !players 

return <CustDropDown disabled={disabled} />
Sign up to request clarification or add additional context in comments.

2 Comments

logical OR instead of bitwise OR
it was a typo bro

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.