0

In my project, I have a button which I want to disable using state.

<Button 
    color='success' 
    onClick={this.changeForm}
    block
    disabled
    >
    LOGIN
</Button>

I am using Reactstrap. I have a flag value set in the state. I want to disable the button if flag is set to TRUE. So, I came up with this code:

<Button 
    color='success' 
    onClick={this.changeForm}
    block
    {this.state.flag && 'disabled'}
    >
    LOGIN
</Button>

I am getting Syntax Error. I understand that that's a not proper syntax so how can I achieve the functionality that I want?

1 Answer 1

3

disabled is a prop of Button. Thus:

<Button 
    color='success' 
    onClick={this.changeForm}
    disabled={this.state.flag}
    >
    LOGIN
</Button>
Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely not stupid. You don’t know until you know ;)

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.