๐ค ์์งlog ๐ค
[REACT] react-daum-postcode๋ฅผ ์ด์ฉํ์ฌ ์ฐํธ๋ฒํธ ๊ฒ์ ๊ตฌํํ๊ธฐ ๋ณธ๋ฌธ
๐ React
[REACT] react-daum-postcode๋ฅผ ์ด์ฉํ์ฌ ์ฐํธ๋ฒํธ ๊ฒ์ ๊ตฌํํ๊ธฐ
Eun_zii 2023. 10. 30. 16:05
์นด์นด์ค์์ ์ ๊ณตํ๋ ์ฐํธ๋ฒํธ ์๋น์ค ๋ฅผ
๋ฆฌ์กํธํ๊ฒฝ์์ ์กฐ๊ธ ๋ ๊ฐํธํ๊ฒ ์ด์ฉํ ์ ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ด์ ์ฌ์ฉํด๋ดค๋ค ใ !
npm i react-daum-postcode
์๋ฒ ๋ ํด์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ ๊ณผ ํ์ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ด ์๊ณ , ๋๋ ํ์ ๋ฐฉ์์ผ๋ก ๊ตฌํํด๋ณด์๋ค.
โ ์ ์ฒด ์ฝ๋
import React, { useState } from "react";
import styled from "styled-components";
import { useDaumPostcodePopup } from "react-daum-postcode";
import { postcodeScriptUrl } from "react-daum-postcode/lib/loadPostcode";
const PostCode = () => {
const open = useDaumPostcodePopup(postcodeScriptUrl);
const [address, setAddress] = useState("");
const [detailAddress, setDetailAddress] = useState("");
const [extraAddress, setExtraAddress] = useState("");
const [zonecode, setZonecode] = useState("");
const handleComplete = (data: {
address: any;
addressType: string;
bname: React.SetStateAction<string>;
buildingName: string;
zonecode: string;
}) => {
let fullAddress = data.address;
if (data.addressType === "R") {
if (data.bname !== "") {
fullAddress += " " + data.bname;
}
if (data.buildingName !== "") {
fullAddress += " " + data.buildingName;
}
}
setAddress(fullAddress);
setExtraAddress(data.bname);
setDetailAddress("");
setZonecode(data.zonecode);
};
const handleClick = () => {
open({ onComplete: handleComplete });
};
return (
<Input>
<div className="row">
<div className="col">
<input placeholder="์ฐํธ๋ฒํธ" value={zonecode} readOnly />
<input
type="button"
defaultValue="์ฐํธ๋ฒํธ ์ฐพ๊ธฐ"
onClick={handleClick}
style={{
border: "2px solid black",
}}
readOnly
/>
</div>
</div>
<input
placeholder="์ฃผ์"
defaultValue={address}
style={{ width: "130%" }}
readOnly
/>
<input
placeholder="์์ธ์ฃผ์"
defaultValue={detailAddress}
onChange={(e) => setDetailAddress(e.target.value)}
style={{ width: "100%" }}
/>
</Input>
);
};
const Input = styled.div`
input {
margin: 5px 5px 5px;
padding: 5px 5px 5px;
font-size: 28px;
border-radius: 5px;
}
`;
export default PostCode;
์ ๋ง ๊ฐ๋จํ๊ฒ ์-์ฑ ใ -๐
728x90
'๐ React' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[REACT] beforeunload ํ์ด์ง ๋๊ฐ๋ / ์๋ก๊ณ ์นจ ํ ๋ alert ๋์ฐ๊ธฐ (0) | 2023.11.13 |
---|---|
[REACT] ํ๋ก ํธ์๋ ๊ธฐ์ ๋ฉด์ ๊ฐ๋ ์ ๋ฆฌ (1) | 2023.11.02 |
[REACT] React-webcam ๊ตฌํํ๊ธฐ (0) | 2023.10.19 |
[REACT] Infinite scroll (๋ฌดํ์คํฌ๋กค) ๊ตฌํํ๊ธฐ (0) | 2023.10.13 |
[REACT] QueryClient , Query Invalidation (0) | 2023.09.25 |