I am new to React JS still learning a lot. I created another js file (Loading.js) which is I want it to be a loader on my onClick event specifically on (New Client button) && (Manage Account button)
import React from 'react';
import Loading from './Loading';
import '../Styles.scss';
Modal,
Icon,
} from 'semantic-ui-react';
function InvestNow() {
return (
<div>
<Button
onClick={() => {
window.location.href = '/';
//* ADD Loading.js here
}}
color="yellow"
fluid
icon
labelPosition="left">
<Icon name="plus" />
New Client
</Button>
</div>
);
}
export default InvestNow
This is the Loader I created from react-loader-spinner
My Loading.js
import React, { Component } from 'react';
import Loader from 'react-loader-spinner';
import '../Styles.scss';
import 'react-loader-spinner/dist/loader/css/react-spinner-loader.css';
class Loading extends React.Component {
render() {
return (
<Loader
type="Bars"
color="#FFD400"
height={450}
width={100}
timeout={5000} //3 secs
className="Loadingstyle"
/>
);
}
}
export default Loading;
InvestNowcomponent to track whether or not the loading should be shownconst [loading, setLoading] = React.useState(false);you can then set loading to true in your clicksetLoading(true); To display your loader you can conditionally display it using{ !!loading && <Loading /> }