μ€λ λ°°μ΄κ²λ€ μ 리
π‘ 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 [λͺ¨λ μ΄λ¦] μλνλ λ΄ μ λ©μΆ° π¨