react-daumpost-hook 1.0.8 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,39 +12,42 @@
12
12
  ## 설치
13
13
 
14
14
  ```shell
15
- npm install --save react-daumpost-hook
15
+ npm install react-daumpost-hook
16
+ //or
17
+ yarn add react-daumpost-hook
16
18
  ```
17
19
 
18
20
  ## 사용법
19
21
 
22
+ ### 팝업 방식 사용
23
+
20
24
  ```js
21
- import React, { useRef } from 'react';
25
+ import React from 'react';
22
26
  import ReactDaumPost from 'react-daumpost-hook';
23
27
 
24
28
  const App = function () {
25
29
  const ref = useRef(null);
26
30
 
27
31
  const postConfig = {
28
- ref : ref,
32
+ // 팝업창으로 사용시 ref: userRef()
29
33
  onComplete : (data) => {
30
- console.log(data);
31
- // 검색후 해당 컴포넌트를 다시 안보이게 하는 부분
32
- ref.current.style.display= "none";
34
+ /*
35
+ 우편 번호 처리하는 로직
36
+ */
33
37
  }
34
38
  };
35
39
  const postCode = ReactDaumPost(postConfig);
36
40
 
37
41
  return (
38
42
  <main>
39
- test
40
- <input type="text" onClick={() => postCode()} />
41
- <div ref={ref}></div>
43
+ 우편번호찾기
44
+ <input type="text" onClick={postCode} />
42
45
  </main>
43
46
  );
44
47
  };
45
48
  ```
46
49
 
47
- ### react-hook-form을 같이 쓸 경우
50
+ ### 기존 DOM에 삽입 + react-hook-form을 같이 쓸 경우
48
51
 
49
52
  ```js
50
53
  import React, { useRef } from 'react';
@@ -57,9 +60,9 @@ const App = function () {
57
60
  const ref = useRef(null);
58
61
 
59
62
  const postConfig = {
60
- ref : ref,
63
+ ref : ref, //팝업창으로 사용시 해당 파라메터를 없애면 된다.
61
64
  onComplete : (data) => {
62
- // 데이터를 받아와서 Set해주는 부분
65
+ // 데이터를 받아와서 set해주는 부분
63
66
  setValue('address', data.address);
64
67
  handleSubmit((data) => console.log(data))();
65
68
  // 검색후 해당 컴포넌트를 다시 안보이게 하는 부분
@@ -70,9 +73,9 @@ const App = function () {
70
73
 
71
74
  return (
72
75
  <main>
73
- test
74
- <input type="text" onClick={() => postCode()} />
75
- <div ref={ref}></div>
76
+ 우편번호찾기
77
+ <input type="text" onClick={postCode} />
78
+ <div ref={ref}>/* 이곳에 검색창이 삽입 됩니다.*/</div>
76
79
  </main>
77
80
  );
78
81
  };
@@ -83,16 +86,22 @@ const App = function () {
83
86
  ```js
84
87
  import ReactDaumPost from 'react-daumpost-hook';
85
88
  ```
86
- 에서 불러온 ReactDaumPost 함수를 실행시키면 다음 우편 주소 API 스크립트를 로딩하며 해당 주소 API를 실행 시킬 수 있는 함수를 반환합니다.
87
- 반환 함수를 원하시는 컴포넌트의 이벤트에 연결하시면 다음 우편주소 API를 사용 하실 수 있습니다.
88
- ReactDaumPost Hook을 실행시킬때 임의의 config객체를 인자로 넘겨서 API 설정합니다.
89
-
90
- ### CONFIG 구성
91
-
92
- 1. **ref (?ref)** : 다음 API 포스트코드 검색창을 삽입시킬 컴포넌트입니다. useRef를 통해서 셀렉한 ref를 넘깁니다., **해당 속성을 비워두시면 자동으로 우편코드 검색 창을 팝업 방식**으로 띄웁니다.
93
- 2. **apiUrl (?string)** : 다음 API 스크립트 경로입니다. 선택사항이며 제공되는 API 경로가 변경된 경우 해당 값으로 변경해주시면 됩니다.
94
- **기본값은 "t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"** 입니다.
95
- 3. **method (?object)** : 다음 API에서 제공되는 **생성자들을 사용하실 경우 제공되는 인터페이스**입니다. 아래와 같이 객체를 생성하여서 method 인수로 넘겨주시면됩니다.
89
+ 에서 불러온 ReactDaumPost 함수를 호출하면 다음 우편 주소 API 스크립트를 html에 삽입하며 해당 주소 API를 불러올 수 있는 함수를 반환합니다. 반환 된 함수를 원하시는 컴포넌트의 이벤트에 바인딩하시면 해당 이벤트로 다음 우편주소 API를 호출 할 수 있습니다.
90
+ API 설정의 경우 ReactDaumPost 함수를 호출할때 props 객체를 인자로 넘겨서 API를 설정합니다.
91
+ * 해당 패키지의 경우 바닐라js로 구성 되어서 간단하게 API 로직을 캡슐화 하고 있습니다.
92
+ 팝업 방식으로 쓰신다면 js 기반 프로젝트라면 어디서든 상관 없습니다.
93
+ 다만 타입스크립트의 사용시 리액트 기반으로 타입추론을 하고 있습니다.
94
+
95
+ ### PROPS
96
+ > config자체를 넘기지 않을 경우 console에 검색결과를 출력 합니다.
97
+
98
+ 1. **`ref (?ref)`** : 다음 우편번호 찾기 검색창을 삽입시킬 컴포넌트입니다. useRef를 통해서 셀렉한 ref를 넘깁니다., **해당 속성을 비워두시면 자동으로 우편코드 검색 창을 팝업 방식**으로 띄웁니다.
99
+
100
+ 2. **`apiUrl (?string)`** : 다음 API 스크립트 경로입니다. 선택사항이며 제공되는 API 경로가 변경된 경우 해당 값으로 변경해주시면 됩니다.
101
+ **`기본값은 "t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"`** 입니다.
102
+
103
+ 3. **`method (?object)`** : 다음 API에서 제공되는 **생성자들을 사용하실 경우 제공되는 인터페이스**입니다. 아래와 같이 객체를 생성하여서 method 인수로 넘겨주시면됩니다.
104
+
96
105
  ```js
97
106
  {
98
107
  onresize: function(size) {
@@ -104,15 +113,14 @@ ReactDaumPost Hook을 실행시킬때 임의의 config객체를 인자로 넘겨
104
113
  ```
105
114
  자세한 내용은 [Daum Postcode API 가이드](http://postcode.map.daum.net/guide#usage)에서 참고해주시길 바랍니다.
106
115
 
107
- 4. **onComplete (?function)** : 포스트 API 검색 결과를 처리할 함수를 넘겨주시길바랍니다. 기본 값은 (data) => console.log(data)입니다.
108
-
109
- ***ref, apiUrl, method, onComplete 4가지 인자***를 객체 프로퍼티로 해당 커스텀훅에 넘겨서 사용 할 수 있으며 해당 인자들은 모두 선택사항이며
110
- ***반드시 필요한 속성은 검색결과를 처리할 onComplete 하나***입니다. ref를 통해서 원하는 위치에 검색창을 삽입하시거나 팝업방식으로 간단히 API를
111
- 이용가능하니 참고하셔서 사용해주시고 문의가 있을시 해당 Git Repo에 이슈로 등록해주시길 바랍니다.
112
-
113
-
116
+ 4. **`onComplete (function)`** : API 검색 결과를 처리할 함수를 넘겨주시길바랍니다.
117
+ `config 자체를 안넘길 경우 기본 값은 (data) => console.log(data)입니다.`
118
+
119
+
120
+ ***ref, apiUrl, method, onComplete 4가지 인자*** 를 `config` 프로퍼티로 해당 커스텀훅에 넘겨서 API를 설정할 수 있습니다.
121
+ 4가지 중 ***반드시 필요한 속성은 검색결과를 처리할 onComplete 하나*** 입니다. 를 통해서 원하는 위치에 검색창을 삽입하시거나 팝업방식으로 간단히 API를 이용가능하니 참고하셔서 사용해주시고 문의가 있을시 해당 Git Repo에 이슈로 등록해주시길 바랍니다.
114
122
 
115
123
 
116
- ### License
124
+ ### LICENSE
117
125
 
118
126
  react-daumpost-hook is [MIT licensed](./LICENSE).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-daumpost-hook",
3
- "version": "1.0.8",
4
- "description": "다음 포스트 코드 API 커스텀훅",
3
+ "version": "1.1.5",
4
+ "description": "다음 카카오에서 무료로 제공하는 우편번호(주소찾기) API 쉽게 기존 코드에 연결 할 수 있는 hook 패키지 입니다.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
7
7
  "scripts": {
@@ -15,7 +15,17 @@
15
15
  "react",
16
16
  "daum",
17
17
  "postcode",
18
- "hook"
18
+ "hook",
19
+ "kakao",
20
+ "우편번호",
21
+ "주소찾기",
22
+ "커스텀훅",
23
+ "daum address",
24
+ "address",
25
+ "korea",
26
+ "daum postcode",
27
+ "kakao postcode",
28
+ "kakao address"
19
29
  ],
20
30
  "files": [
21
31
  "src",
@@ -28,7 +38,6 @@
28
38
  },
29
39
  "homepage": "https://github.com/yoonjonglyu/react-daumpost-hook#readme",
30
40
  "dependencies": {
31
- "prop-types": "^15.7.2",
32
41
  "react": "^17.0.2"
33
42
  }
34
43
  }
package/src/index.d.ts CHANGED
@@ -1,26 +1,26 @@
1
- export {};
1
+ import React from 'react';
2
+
3
+ export { };
2
4
  declare global {
3
5
  interface Window {
4
6
  daum?: any;
5
7
  }
6
-
8
+
7
9
  }
10
+
8
11
  declare module 'react-daumpost-hook' {
9
- import React from 'react';
12
+ const ReactDaumPost: ReactDaumPost
10
13
 
11
- const ReactDaumPost : ReactDaumPost
12
-
13
14
  interface ReactDaumPost {
14
- (config : ReactDaumPostProps) : Function
15
+ (config?: ReactDaumPostProps): VoidFunction
15
16
  }
16
17
 
17
18
  interface ReactDaumPostProps {
18
- ref? : React.MutableRefObject<null>,
19
- onComplete? : Function,
20
- apiUrl? : string,
21
- method? : Object
19
+ ref?: React.MutableRefObject<any>,
20
+ onComplete: VoidFunction,
21
+ apiUrl?: string,
22
+ method?: Object
22
23
  }
23
24
 
24
- export { ReactDaumPostProps, ReactDaumPost }
25
25
  export default ReactDaumPost;
26
26
  }
package/src/index.js CHANGED
@@ -1,4 +1,2 @@
1
1
  import ReactDaumPost from './reactDaumPostHook';
2
-
3
- export { ReactDaumPost };
4
2
  export default ReactDaumPost;
@@ -1,4 +1,4 @@
1
- const ReactPostCodeHook = function (props) {
1
+ function daumPostCodeHook(props) {
2
2
  const {
3
3
  ref,
4
4
  apiUrl,
@@ -8,41 +8,41 @@ const ReactPostCodeHook = function (props) {
8
8
 
9
9
  // 내부 변수들 더블 언더바 를 prefix로 사용
10
10
  const __postcodeUrl = apiUrl !== undefined ? apiUrl : "//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js";
11
- const __scriptId = "DPCKAKAO#$%!@#@@$@#@$#";
11
+ const __scriptId = "daumpostcodemapv2";
12
12
  const __method = method !== undefined ? method : {};
13
13
  const __onComplete = onComplete !== undefined ? onComplete : (data) => console.log(data);
14
14
 
15
15
 
16
16
  // 스크립트가 없을시 로드 해오는 부분
17
- if (!document.getElementById(__scriptId)) {
17
+ if (document.getElementById(__scriptId) === null) {
18
18
  const __postCodeScript = document.createElement('script');
19
19
  __postCodeScript.id = __scriptId;
20
20
  __postCodeScript.src = __postcodeUrl;
21
- document.body.appendChild(__postCodeScript);
21
+ document.head.appendChild(__postCodeScript);
22
22
  }
23
23
 
24
- const getPostCode = function () {
25
- if(ref === undefined){
24
+ const getPostCode = () => {
25
+ if (ref === undefined) {
26
26
  getPostCodePopup();
27
27
  } else {
28
28
  getPostCodeEmbed();
29
29
  }
30
30
  }
31
31
 
32
- const getPostCodeEmbed = function (){
32
+ const getPostCodeEmbed = () => {
33
33
  new window.daum.Postcode({
34
34
  oncomplete: __onComplete,
35
35
  onresize: function (size) {
36
36
  ref.current.style.height = size.height + 'px';
37
37
  },
38
- width : "100%",
39
- height : "100%",
38
+ width: "100%",
39
+ height: "100%",
40
40
  ...__method
41
41
  }).embed(ref.current);
42
42
  ref.current.style.display = 'block';
43
43
  }
44
44
 
45
- const getPostCodePopup = function (){
45
+ const getPostCodePopup = () => {
46
46
  new window.daum.Postcode({
47
47
  oncomplete: __onComplete,
48
48
  ...__method
@@ -52,4 +52,4 @@ const ReactPostCodeHook = function (props) {
52
52
  return getPostCode;
53
53
  }
54
54
 
55
- export default ReactPostCodeHook;
55
+ export default daumPostCodeHook;