callstack / callstack/react-native-paper
Replace status prop with checked in ToggleButton component
- Dominant language
- TypeScript
- Stars
- 14.5k
- Forks
- 2.2k
- Avg merge
- 5d 23h
- Merged PRs (30d)
- 12
Description
**Is your feature request related to a problem? Please describe.**
The `ToggleButton` component currently uses a `status` prop with string values `checked` | `unchecked`. This adds unnecessary complexity for a binary state.
**Describe the solution you'd like**
Replace the `status` prop with a boolean `checked` prop.
Before:
```typescript
const ToggleButtonExample = () => {
const [status, setStatus] = React.useState('checked');
const onButtonToggle = () => {
setStatus(status === 'checked' ? 'unchecked' : 'checked');
};
return (
);
};
```
After:
```typescript
const ToggleButtonExample = () => {
const [isChecked, setIsChecked] = React.useState(true);
const onButtonToggle = () => {
setIsChecked(s => !s);
};
return (
);
};
```
**Additional context**
A boolean checked prop is simpler, clearer, and more consistent with common React patterns than using string values like 'checked' and 'unchecked'.
Contributor guide
Assessment
This issue has not been assessed yet.