callstack / callstack/react-native-paper

Replace status prop with checked in ToggleButton component

Open
#4,866 0 comments 0 reactions 0 assignees View on GitHub
feature request
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.