Intro
react-datepicker λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νλ λμ€ CSS κ° μ μ© μλλ μλ¬κ° λ°μνμ΅λλ€. μ°Έκ³ λ‘ μ λ νμ μ€ν¬λ¦½νΈλ μ μ©ν΄μΌ νκΈ° λλ¬Έμ λΌμ΄λΈλ¬λ¦¬ μ€μΉλ μλμ κ°μ΄ μ§ννμμ΅λλ€.
yarn add react-datepicker
yarn add @types/react-datepicker
react-datepicker 곡μ ννμ΄μ§μ μλ Default μμ λ₯Ό μ½λμ λ£μ΄ μ€ννμ, cssκ° μ ν μ μ©λμ§ μλ μνλ‘ νλ©΄μ λ¨λκ΅°μ.
() => {
const [startDate, setStartDate] = useState(new Date());
return (
<DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
);
};
Why?
λ°λ‘ ꡬκΈλ§μ ν΄λ΄€μ΅λλ€. μ μ λΉμ·ν μλ¬λ₯Ό κ²ͺμΌμ λΆλ€μ΄ λ§μμ΅λλ€.
https://github.com/Hacker0x01/react-datepicker/issues/879
λ± μ΄ κΈμ μ°μ λΆκ³Ό μ μν©μ΄ μ μ¬νλ€κ³ 보면 λ©λλ€. λ΅λ³λ κ΅μ₯ν λ§μ΄ λ¬λ Έλ€μ. μ΄ν μ λ react-datepicker 곡μ νμ΄μ§λ μ΄ν΄λ³΄μμ΅λλ€.
You’ll need to install React and PropTypes separately since those dependencies aren’t included in the package. If you need to use a locale other than the default en-US, you'll also need to import that into your project from date-fns (see Localization section below). Below is a simple example of how to use the Datepicker in a React view. You will also need to require the CSS file from this package (or provide your own). The example below shows how to include the CSS from this package if your build system supports requiring CSS files (Webpack is one that does).
import React, { useState } from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
// CSS Modules, react-datepicker-cssmodules.css
// import 'react-datepicker/dist/react-datepicker-cssmodules.css';
const Example = () => {
const [startDate, setStartDate] = useState(new Date());
return (
<DatePicker selected={startDate} onChange={(date) => setStartDate(date)} />
);
};
μ§μ cssλ₯Ό λͺ μν΄μΌ, css νμΌμ μ¬μ©ν μ μμκ΅°μ..
How to solve the problem
date-pickerλ₯Ό μ¬μ©νλ νμΌμ λ€μκ³Ό κ°μ΄ cssλ₯Ό λͺ μνμ¬ import ν΄μ£Όμμ΅λλ€. λ€νν cssκ° μ μ©μ΄ λλ€μ.
import "react-datepicker/dist/react-datepicker.css"
+) cssκ° μ μ©λκΈ΄ νλλ°..
μ΄μ§ μ°κ·Έλ¬μ Έμ μ μ©μ΄ λλλΌκ³ μ? π€« μ΄ λ¬Έμ λ μ λ§ κ·Έλ°κ±΄μ§.. λ€μ νλ² μ°κ΅¬ν΄ λ΄μΌ λ κ² κ°μ΅λλ€.
'Framework > React' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Modern React] section1 : Let's Dive in! (0) | 2023.01.08 |
---|---|
[React] react-datepicker νΉμ /μ§λ λ μ§ μ μΈνλ λ°©λ² (0) | 2023.01.04 |
[React] React.FC μ μλ―Έμ μ¬μ©νμ§ μλ μ΄μ (0) | 2022.10.02 |
[React] innerHTML & λμ μΌλ‘ HTML μ½λ μΆκ°νλ λ°©λ² (0) | 2022.10.02 |
[React] Warning: validateDOMNesting(...): <div> cannot appear as a child of <tbody> μ€λ₯ (1) | 2022.10.01 |