0

I am trying to add Bootstrap 4 Loading Spinner on a button. My button code is like below

<button className="btn-wide btn-pill btn-shadow btn-hover-shine btn btn-primary btn-lg"
                          onClick={this.handleSubmit}>
   {
      this.state.toggle && this.props.value !== 'error'
           ? '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>'
    : ''
   }
   Create Account
  </button>

I am getting output like below

enter image description here

I included Bootstrap 4 in index.html file like below

<title>React App</title>
    <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

  </head>

1 Answer 1

2
<button className="btn-wide btn-pill btn-shadow btn-hover-shine btn btn-primary btn-lg"
                      onClick={this.handleSubmit}>
   {
      this.state.toggle && this.props.value !== 'error' &&
           <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
   }
   Create Account
</button>

This will let react know that you want to render the <span> element instead of writing it as button label.

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

2 Comments

Thanks @Anand Popat. But why my way is not working ?
Because you wrapped it inside single quotes and react will render anything inside quotes as text.

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.