This is a quick save for anyone looking to add a loading button for Bootstrap in React.
Note: You must install peer dependency bootstrap and import the bootstrap stylesheet
- Install the package and bootstrap
npm install react-bootstrap-button bootstrapFor other installation methods of bootstrap styles, refer to guides from the official bootstrap documentation.
- Import bootstrap stylesheet in your App.js:
import'../node_modules/bootstrap/dist/css/bootstrap.min.css';import{BootstrapButton}from'react-bootstrap-button';constComponent=()=>{// other code above...const[clicked,setClicked]=useState(false);consthandleClick=()=>setClicked(true);return(<BootstrapButtonvariant="danger"// You may include all react-bootstrap button propsclassName="m-4".isLoading={clicked}loadingMessage="This button is loading..."onClick={handleClick}>
Click me
</BootstrapButton>);// other code below...};Properties for <BootstrapButton> includes those from React-Bootstrap Button and the following:
typeBootstrapButton={isLoading?: boolean;isDisabled?: boolean;spinnerPosition?: 'left'|'right';spinnerProps?: SpinnerProps;// see React Spinner Props ApiloadingMessage?: string;leftIcon?: ReactElement;};MIT Licence