Skip to content

Commit

Permalink
fix(usephoneinput): fixed unable to detect country when received valu…
Browse files Browse the repository at this point in the history
…e on mount
  • Loading branch information
trinhthinh388 committed Jan 31, 2024
1 parent 8f36849 commit 56b77f4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"clean": "rimraf .turbo && rimraf node_modules && rimraf .next"
},
"dependencies": {
"@react-awesome/components": "1.0.6",
"@react-awesome/components": "1.0.7",
"classnames": "^2.5.1",
"lucide-react": "^0.315.0",
"next": "^14.0.4",
Expand Down
7 changes: 7 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @react-awesome/components

## 1.0.7

### Patch Changes

- Updated dependencies
- @react-awesome/phone-input@1.0.6

## 1.0.6

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-awesome/components",
"version": "1.0.6",
"version": "1.0.7",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
"access": "public"
},
"dependencies": {
"@react-awesome/phone-input": "1.0.5",
"@react-awesome/phone-input": "1.0.6",
"@react-awesome/use-click-outside": "0.0.3",
"@react-awesome/use-preserve-input-caret-position": "0.0.3",
"@react-awesome/use-selection-range": "0.0.3",
Expand Down
8 changes: 8 additions & 0 deletions packages/phone-input/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @react-awesome/phone-input

## 1.0.6

### Patch Changes

- Bug fixes:

- `usePhoneInput` doesn't detect country when received `value` on mount.

## 1.0.5

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/phone-input/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-awesome/phone-input",
"version": "1.0.5",
"version": "1.0.6",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
7 changes: 5 additions & 2 deletions packages/phone-input/src/hooks/usePhoneInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const usePhoneInput = ({
}

return {
phone: value || '',
phone: '',
country: getInitialCountry(),
}
})
Expand Down Expand Up @@ -245,12 +245,15 @@ export const usePhoneInput = ({
React.useEffect(() => {
if (!value) return
if (value !== innerValue.phone) {
const metadata = generateMetadata(value, innerValue.country)
onPhoneChange(undefined, metadata)
setInnerValue((prev) => ({
...prev,
country: metadata.country,
phone: value,
}))
}
}, [innerValue, onPhoneChange, value])
}, [generateMetadata, innerValue, onPhoneChange, value])

return {
inputEl: inputRef,
Expand Down

0 comments on commit 56b77f4

Please sign in to comment.