React
-
리액트 타입스크립트 스타일컴포넌트 Theme 적용하기React/React+TypeScript 2023. 2. 22. 03:06
1. styled.d.ts 파일을 만든다. 속에 interface 를 만든다. import "styled-components"; declare module "styled-components" { export interface UsingTheme { textColor: string; bgColor: string; btnColor: string; } } 2. 해당 interface 를 적용할 theme.ts 를 만든다. (단 여기서 UsingTheme 부분이 defaultTheme 로 쓰이면 안된다. 해당 단어는 기본설정이라 변경하면 다 적용되어버린다.) import { UsingTheme } from "styled-components"; export const lightTheme: UsingTheme = ..
-
React+TypeScript Form 형식을 공부해보자!React/React+TypeScript 2023. 2. 22. 02:58
📌 e : React.FormEvent ...(중략) const [value, setValue] = useState(""); const onchange = (e: React.FormEvent) => { const { value } = e.currentTarget; setValue(value); }; const onSubmit = (e: React.FormEvent) => { e.preventDefault(); console.log(`Hello ${value}`) }; return ( Log in )
-
? / ?? 리액트 타입스크립트 props 전달할때 optional Chaining & null CheckReact/React+TypeScript 2023. 2. 21. 20:37
📌 지난 시간 리액트 타입스크립트 기반으로 props 를 전달해주는 방법을 배웠다. optional chaining 은 해당 prop은 전달되지 않을 수도 있다는 표현을 해줄 때 사용한다. personobj.name 은 .(chaining) personobj?.name 은 ?.(optional chaining) 이 된다. 즉 왼쪽 값이 비어있다면 해당 코드를 undefined 처리하라는 것과 같다. 아래 코드에서 추가로 보면 // interface 를 통해 전달하려고 하는 props 들의 타입을 지정해준다. interface personobj { name : string, age? : number // 🔥age가 비어있을 수도 있다. 라는 것을 암시한다. //age : number | undefined ..
-
React + TypeScript 에서 props 전달하는 법 with styled-componentsReact/React+TypeScript 2023. 2. 21. 19:51
📌 TypeScript 타입스크립트 기반 React 에서 props 를 전달하려면 어떻게 해야할까? // interface 를 통해 전달하려고 하는 props 들의 타입을 지정해준다. interface personobj { name : string, age : number } // 전달하려는 props 뒤에 interface 를 지정해준다. const SayHello = ({name, age} : personobj) =>{ return( sayHello {name} you are {age} ) } function App() { return } 📌 그렇다면 Styled-components 스타일 컴포넌트에 props 를 전달하려면 어떻게 해야할까? interface BoxProps { bgcolor : s..
-
Styled-Components 의 애니메이션 과 Pseudo Selector 를 배워보자!React/Styled-Components 2023. 2. 20. 21:34
📌 css 에서 keyframe 을 사용한 animation 은 styled-components에서 어떻게 구현할까? ...(중략) const animation1 = keyframes` from { transform:rotate(0deg); border-radius: 0px; } to { transform:rotate(360deg); border-radius: 100px; } `; ...(중략) const AnimationBox1 = styled.div` height: 200px; width: 200px; background-color: black; animation: ${animation1} 10s linear infinite; `; ...(중략) 📌 styled-components 안에서 pseudo..
-
Styled-Components 의 as 와 attrs 를 알아보자!React/Styled-Components 2023. 2. 20. 20:27
📌 스타일 속성은 같은데 태그만 바꾸고 싶을 땐 어떻게 할까? as 를 통해 기존 button 태그였던 것을 a 태그로 바꿀 수 있다! return button 📌 태그에 속성을 부여하고 싶다면 attrs를 사용해보자! 스타일 컴포넌트로 생성한 Input 은 required 와 maxLength 를 속성으로 가질 수 있다! const Input = styled.input.attrs({ required: true, maxLength: 10 })``;
-
Styled-Components 리액트 스타일 컴포넌트 props 와 extendingReact/Styled-Components 2023. 2. 20. 17:50
📌 스타일 컴포넌트에서 반복되는 코드를 줄일 수는 없는걸까? const BoxOne = styled.div` background-color: red; width: 100px; height: 100px; `; const BoxTwo = styled.div` background-color: blue; width: 100px; height: 100px; `; 📌 해결방안 : props 로 변수를 지정해주며 styled( ) 로 확장할 수 있다. ...(중략) const Box = styled.div` display: flex; align-items: center; background-color: ${(props) => props.bgcolor}; width: 100px; height: 100px; `; con..