Skip to content

Commit ef24c0c

Browse files
authored
Update README.md
1 parent 94bc1a8 commit ef24c0c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,51 @@ innerIconStyle={{
311311
}}
312312
```
313313

314+
<b>How to use multiple checkbox and control all of them with one checkbox?</b>
315+
316+
- You can use `isChecked` prop to control all of them one by one and with simple handling function to make them all checked or not
317+
318+
```tsx
319+
const data = [
320+
{
321+
id: 0,
322+
isChecked: false,
323+
},
324+
{
325+
id: 1,
326+
isChecked: false,
327+
},
328+
{
329+
id: 2,
330+
isChecked: false,
331+
},
332+
]
333+
334+
const [checkBoxes, setCheckBoxes] = useState(data);
335+
336+
337+
const handleCheckboxPress = (checked: boolean, id: number) => {
338+
if (id === 0) {
339+
setCheckBoxes(
340+
checkBoxes.map(item => ({
341+
...item,
342+
isChecked: checked,
343+
})),
344+
);
345+
return;
346+
}
347+
348+
setCheckBoxes(
349+
checkBoxes.map(item =>
350+
item.id === id ? {...item, isChecked: checked} : item,
351+
),
352+
);
353+
};
354+
```
355+
356+
Please check out the example for this:
357+
https://github.com/WrathChaos/react-native-bouncy-checkbox-check-all-with-one-checkbox
358+
314359
### Future Plans
315360
316361
- [x] ~~LICENSE~~

0 commit comments

Comments
 (0)