Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- FOR
- htmlFor
- createtextnode
- 학습법 #집중력
- VAR
- appendChild
- createElement
- boolean
- input
- Let
- const
- Append
- Openlayers
Archives
- Today
- Total
Atomic Habits
[checkAll] ! ! list .length ? boolean ? 본문
import React from 'react'
import { Checkbox, Divider } from 'antd';
const CheckboxGroup = Checkbox.Group;
const plainOptions = ['Apple', 'Pear', 'Orange'];
const defaultCheckedList = ['Apple', 'Orange'];
export default function FormEx1() {
const [checkedList, setCheckedList] = React.useState(defaultCheckedList);
const [indeterminate, setIndeterminate] = React.useState(true);
const [checkAll, setCheckAll] = React.useState(false);
const onChange = list => {
setCheckedList(list);
★ setIndeterminate(!!list.length && list.length < plainOptions.length);
alert("list.length : "+list.length); // 2
alert("!list.length : "+!list.length); // false (2의 반대)
alert("!!list.length : "+!!list.length); // true (2의 반대의 반대)
setCheckAll(list.length === plainOptions.length);
};
const onCheckAllChange = e => {
setCheckedList(e.target.checked ? plainOptions : []);
setIndeterminate(false);
setCheckAll(e.target.checked);
};
return (
<>
<Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
Check all
</Checkbox>
<Divider />
<CheckboxGroup options={plainOptions} value={checkedList} onChange={onChange} />
</>
)
}
'IT > React' 카테고리의 다른 글
React. Part2. ch3. 10~12. Material UI 1,2,3 (0) | 2021.11.14 |
---|---|
[VS CODE] React Code Snippets (0) | 2021.11.14 |
React. Part2. ch2. 04. emotion 2 (0) | 2021.11.12 |
React. Part2. ch2. 03. emotion 1 (0) | 2021.11.12 |
React. Part2. ch2. 02-2. styled-components (0) | 2021.11.11 |
Comments