Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: unregister.mdx #33

Open
wants to merge 1 commit into
base: master-ko
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/content/docs/useform/unregister.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: unregister
description: Unregister uncontrolled/controlled inputs
description: 비제어, 제어 input Unregister
sidebar: apiLinks
---

## \</> `unregister:` <TypeText>(name: string | string[], options) => void</TypeText>

This method allows you to `unregister` a single input or an array of inputs. It also provides a second optional argument to keep state after unregistering an input.
이 메서드를 사용하면 단일 input 또는 input 배열을 `unregister`할 수 있습니다. 또한 input을 unregister한 후 상태를 유지하기 위한 두 번째 선택적 인수를 제공합니다.

### Props

---

The example below shows what to expect when you invoke the `unregister` method.
아래 예시는 `unregister` 메서드를 호출할 때 예상되는 상황을 보여줍니다.

```javascript
<input {...register('yourDetails.firstName')} />
Expand All @@ -29,19 +29,19 @@ The example below shows what to expect when you invoke the `unregister` method.

---

| Name | Type | Description |
| ------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `keepDirty` | <TypeText>boolean</TypeText> | `isDirty` and `dirtyFields` will be remained during this action. However, this is not going to guarantee the next user input will not update `isDirty` formState, because `isDirty` is measured against the `defaultValues`. |
| `keepTouched` | <TypeText>boolean</TypeText> | `touchedFields` will no longer remove that input after unregister. |
| `keepIsValid` | <TypeText>boolean</TypeText> | `isValid` will be remained during this action. However, this is not going to guarantee the next user input will not update `isValid` for schema validation, you will have to adjust the schema according with the unregister. |
| `keepError` | <TypeText>boolean</TypeText> | `errors` will not be updated. |
| `keepValue` | <TypeText>boolean</TypeText> | input's current `value` will not be updated. |
| `keepDefaultValue` | <TypeText>boolean</TypeText> | input's `defaultValue` which defined in `useForm` will be remained. |
| Name | Type | Description |
| ------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `keepDirty` | <TypeText>boolean</TypeText> | 이 작업을 수행하는 동안 `isDirty``dirtyFields`는 유지됩니다. 그러나 `isDirty`는 `defaultValues`에 대해 측정되기 때문에 다음 사용자 입력이 `isDirty` formState를 업데이트하지 않는다고 보장하지는 않습니다. |
| `keepTouched` | <TypeText>boolean</TypeText> | `touchedFields`는 unregister후 더 이상 해당 입력을 제거하지 않습니다. |
| `keepIsValid` | <TypeText>boolean</TypeText> | 이 작업 중에는 `isValid`가 유지됩니다. 그러나 다음 사용자 입력이 스키마 유효성 검사를 위해 `isValid`를 업데이트하지 않는다고 보장하지는 않으므로 unregister에 따라 스키마를 조정해야 합니다. |
| `keepError` | <TypeText>boolean</TypeText> | `errors`가 업데이트되지 않습니다. |
| `keepValue` | <TypeText>boolean</TypeText> | input의 현재 `value`는 업데이트되지 않습니다. |
| `keepDefaultValue` | <TypeText>boolean</TypeText> | `useForm`에 정의된 input의 `defaultValue`는 그대로 유지됩니다. |

<Admonition type="important" title="Rules">

- This method will remove input reference and its value, which means **built-in validation** rules will be removed as well.
- By `unregister` an input, it will not affect the schema validation.
- 이 방법을 사용하면 input 참조와 해당 값이 제거되므로 **내장 유효성 검사** 규칙도 제거됩니다.
- input을 'unregister'하면 스키마 유효성 검사에 영향을 미치지 않습니다.

```javascript
const schema = yup
Expand All @@ -51,17 +51,17 @@ The example below shows what to expect when you invoke the `unregister` method.
})
.required()

unregister("firstName") // this will not remove the validation against firstName input
unregister("firstName") // 이 경우 firstName input에 대한 유효성 검사는 제거되지 않습니다.
```

- Make sure you unmount that input which has `register` callback or else the input will get registered again.
- `register` 콜백이 있는 입력은 반드시 unmount해야 하며, 그렇지 않으면 입력이 다시 register됩니다.

```javascript
const [show, setShow] = React.useState(true)

const onClick = () => {
unregister("test")
setShow(false) // make sure to unmount that input so register not invoked again.
setShow(false) // register가 다시 호출되지 않도록 해당 입력을 unmount해야 합니다.
}

{
Expand All @@ -71,7 +71,7 @@ The example below shows what to expect when you invoke the `unregister` method.

</Admonition>

**Examples:**
**예제:**

---

Expand Down