Dev-diary/일상

였늘 λ°°μš΄κ²ƒλ“€ 정리

ciocio 2022. 4. 18. 23:19

πŸ’‘ 0λΆ€ν„° μ›ν•˜λŠ” μˆ«μžκΉŒμ§€ λͺ¨λ“  수λ₯Ό μš”μ†Œλ‘œ κ°–λŠ” λ°°μ—΄ λ§Œλ“€κΈ°

 

// Array.from()으둜 길이가 10, 값이 (0~9)인 λ°°μ—΄ 생성
const arr = Array.from({length: 10}, (val, idx) => idx);

console.log(arr);         // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(arr.length);  // 10

 

뢈러온 λ°μ΄ν„°μ˜ 인덱슀λ₯Ό κ°€μ§„ 배열을 ν•œλ²ˆμ— 생성 or μ‚­μ œν•΄μ•Όν•˜λŠ” μ΄λ²€νŠΈκ°€ μžˆμ—ˆλŠ”λ°

이 λ•Œ 이 방법을 μœ μš©ν•˜κ²Œ 썼닀. 더 쒋은 방법이 μžˆμ„ μˆ˜λ„ ..?!!

 


πŸ’‘ checkbox νƒ€μž…μ˜ input νƒœκ·ΈλŠ” 'checked' 속성을 κ°–λŠ”λ‹€

 

<label><input type="checkbox" /> 체크 X </label>
<label><input type="checkbox" checked /> 체크 O </label>

 

λ¦¬μ•‘νŠΈμ—μ„œ useRef ν›…μœΌλ‘œ μ²΄ν¬λ°•μŠ€λ₯Ό κ΄€λ¦¬ν•΄μ•Όν•˜λ‚˜ .. κ³ λ―Όν–ˆμ—ˆλŠ”λ°

checked νƒ€μž…μ΄ μžˆλ‹€λŠ” κ±Έ μ•Œκ³  checked = { 쑰건 ? true : false } 으둜 λ‘œμ§μ„ μž‘μ„±ν–ˆλ‹€.

 


πŸ’‘ ν΄λΌμ΄μ–ΈνŠΈ λ‹¨μ—μ„œ 이미지λ₯Ό λ‘œλ“œν•΄μ•Όν•  λ•Œ (ex.localhost:3000) μ‚¬μš©ν•˜λŠ” κ°„λ‹¨ν•œ 방법

 

<img alt="png01" src="img/01.png" />

 

λ‚˜λŠ” μ™œ μ—¬νƒœ 보쑰 μ„œλ²„λ₯Ό μ—΄μ–΄μ„œ (ex.localhost:5000) 이미지λ₯Ό λ‘œλ“œν•΄μ™”λŠ”κ°€ ...

μ„œλ²„κ°€ 없을 땐 κ·Έλƒ₯ (λ¦¬μ•‘νŠΈ κΈ°μ€€) public 폴더 내뢀에

img 폴더 λ§Œλ“€μ–΄μ„œ 이미지 λ„£μ–΄λ†“μœΌλ©΄ μ΄λ ‡κ²Œ μ‰½κ²Œ 뢈러올 수 μžˆλ‹€ !!

 


πŸ’‘ Typescript μ—μ„œ styled-component (μ»€μŠ€ν…€) props λ‚΄λ €μ£ΌκΈ°

 

import styled, { css } from 'styled-components';

interface PropsType {
  isSelected: boolean;
}

const SelectBox = styled.input<PropsType>`
  opacity: 0%;
  background-color: #000;
  // 방법 01
  ${(props) => 
    props.isSelected 
      ? css`
        opacity: 100%;
      `
      : css``
  }
  // 방법 02
  ${(props) =>
    props.isSelected && `
      opacity: 100%;
    `
  }
`

function BasicForm(){
  return (
    <SelectBox type="checkbox" isSelected={ 쑰건 ? true : false }/>
  );    
}

 

HTML νƒœκ·Έμ— μ›ν•˜λŠ” 속성값이 μ—†λ‹€λ©΄,

ν˜Ήμ€ CSSμ—μ„œ κ΄€λ¦¬ν•˜κ³  싢은 μ»€μŠ€ν…€ 속성이 ν•„μš”ν•˜λ‹€λ©΄,

μ΄λ ‡κ²Œ μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•΄μ„œ μ‚¬μš©ν•˜λ©΄ λœλ‹€ !-! νƒ€μž…μŠ€ν¬λ¦½νŠΈλ‘œ μž‘μ„±ν•  λ•Œ μ’‹λ‹€ 😊

 


πŸ’‘ styled-component μ—μ„œ hover 속성 문법 (자꾸 κΉŒλ¨Ήμ–΄μ„œ μΆ”κ°€)

 

import styled from 'styled-components';

const Button = styled.button`
  border: none;
  &:hover{
    color: blue;
  }
`

 

styled-component λž‘ hover 속성 μ‘°ν•© μ•„μ£Ό 유용 ... πŸ‘πŸ‘

 


πŸ’‘ νƒ€μž…μŠ€ν¬λ¦½νŠΈ ν™˜κ²½μ—μ„œ npm λͺ¨λ“ˆ μ„€μΉ˜ν•  λ•Œ λͺ…λ Ήλ¬Έ 주의

 

npm install @types/[λͺ¨λ“ˆ 이름] --save-dev

 

자꾸 npm install [λͺ¨λ“ˆ 이름] μ‹œλ„ν•˜λŠ” λ‚΄ 손 멈좰 😨


 

 

λ°˜μ‘ν˜•