React BootStrap : 화면 중앙에 나타나는 로딩 스피너
인라인 스타일링
import { Spinner } from 'react-bootstrap';
..
if (isLoading) return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spinner animation="border" />
</div>
);
스피너는 기본적으로 부트스트랩 문서에 있지만, 화면 정중앙 정렬하는 속성이 복잡해서 작성한다.
스타일드 컴포넌트로 재사용
만약 저 스타일을 여러 군데서 쓸 것 같다거나, 인라인 스타일링이 복잡해서 분리하고 싶은 경우 Styled-components로 정의하고 export 한 후 다른 곳에서 재사용 해도 된다.
import styled from 'styled-components';
const SpinnerContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
`;
if (isLoading) return (
<SpinnerContainer>
<Spinner animation="border" />
</SpinnerContainer>
);
쓰려는 컴포넌트에서는 import 후 바로 사용하면 된다.
import SpinnerContainer from './SpinnerContainer'; // 경로를 실제 파일 위치에 맞게 조정
function AnotherComponent({ isLoading }) {
if (isLoading) return (
<SpinnerContainer>
<Spinner animation="border" />
</SpinnerContainer>
);
...
}
'Programing > CSS' 카테고리의 다른 글
한 줄 이상 텍스트가 길어지면 ... 으로 표기하기 (0) | 2024.06.25 |
---|---|
Pure React : Modal (0) | 2024.06.22 |
React BootStrap Quick Start (0) | 2024.06.16 |
유저 프로필 이미지, 텍스트 가운데 정렬 기법 (0) | 2024.06.14 |
마우스 호버 시 살짝 커지는 CSS (0) | 2024.06.14 |
댓글