22년 4월 5일(화)
[스파르타코딩클럽] 리액트 기초반 - 4주차
애니메이션 효과를 주는 방법
Keyframes: animation에서 사용하는 속성 중 하나
사용법 (styled-components 사용)
import styled, {keyframes} from "styled-components";
function App() {
return (
<div className="App">
<Box/>
</div>
);
}
const boxAnimation = keyframes`
0%{
border-radius: 0px;
top: 20px;
}
75%{
border-radius: 5px;
top: 50px;
}
100%{
border-radius: 50px;
top: 400px;
}
`
const Box = styled.div`
width: 100px;
height: 100px;
background-color: green;
border-radius: 50px;
position: absolute;
left: 50px;
animation: ${boxAnimation} 2s 1s infinite linear alternate;
`
export default App;
const ListStyle = styled.div`
display: flex;
flex-direction: column;
height: 50vh;
overflow-x: hidden;
overflow-y: auto;
max-height: 50vh;
`;
import React from "react";
import styled from "styled-components";
import { useSelector } from "react-redux";
const Progress = (props) => {
const bucket_list = useSelector((state) => state.bucket.list);
console.log(bucket_list);
let count = 0;
bucket_list.map((b, idx) => {
if (b.completed) {
count++;
}
});
console.log(count);
return (
<ProgressBar>
<HighLight width={(count / bucket_list.length) * 100 + "%"} />
<Dot/>
</ProgressBar>
);
};
const ProgressBar = styled.div`
background: #eee;
width: 100%;
height: 20px;
display: flex;
align-items: center;
border-radius: 10px;
`;
const HighLight = styled.div`
background: #673ab7;
transition: 1s;
width: ${(props) => props.width};
height: 20px;
border-radius: 10px;
`;
const Dot = styled.div`
width: 40px;
height: 40px;
background: #fff;
border: 5px solid #673ab7;
border-radius: 40px;
margin: 0px 0px 0px -20px;
`;
export default Progress;
const Input = styled.div`
max-width: 350px;
min-height: 10vh;
background-color: #fff;
padding: 16px;
margin: 20px auto;
border-radius: 5px;
border: 1px solid #ddd;
display: flex;
& > * {
padding: 5px;
}
& input{
border: 1px solid #888;
width: 70%;
margin-right: 10px;
}
& input:focus {
outline: none;
border: 1px solid #a673ff;
}
& button {
width: 25%;
color: #fff;
border: #a673ff;
background: #a673ff;
}
`;
서버리스: 서버를 신경쓸 필요 없다, 미리 구축해놓은 서버를 필요한만큼만 빌려 쓰면 된다.
BaaS(Backend as a Service) : 흔히 백엔드 하면 떠올리는 것들을 빌려오는 것이다.
프로젝트 만들기 > 이름 만들고 약관 동의 > 프로젝트 애널리틱스 설정
파이어스토어 설정
대시보드에서 파이어스토어 데이터 넣기
yarn add firebase
//firebase.js
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
// firebase 설정과 관련된 개인 정보
};
// firebaseConfig 정보로 firebase 시작
initializeApp(firebaseConfig);
// firebase의 firestore 인스턴스를 변수에 저장
const db = getFirestore();
// 필요한 곳에서 사용할 수 있도록 내보내기
export { db };
import {db} from "./firebase";
import { collection, doc, getDoc, getDocs, addDoc, updateDoc, deleteDoc } from "firebase/firestore";
// 데이터 가져오기 / forEach 반복문처럼 사용
// async await를 통해 통신하기까지 기다려줌
React.useEffect(async() => {
const query = await getDocs(collection(db, 'bucket'));
console.log(query); // 직접적인 데이터 내용이 나오지 않음
query.forEach((doc) => {
console.log(doc.id, doc.data()); // 반복문의 형태로 출력함
});
}, []);
// 데이터 추가하기
addDoc(collection(db,"bucket"), {text:"현우 재수시키기", completed:false})
// 데이터 업데이트 하기 (id값 필요)
const docRef = doc(db, "bucket", "bONVZG5ZGKqT0C9DUVjw");
updateDoc(docRef,{completed: true})
// 데이터 삭제하기 (id값 필요)
const docRef = doc(db, "bucket", "5rBSiTNsogw1ZnqTpsub");
deleteDoc(docRef)