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

Update style guide #21478

Merged
merged 2 commits into from
Jul 8, 2023
Merged
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
26 changes: 12 additions & 14 deletions contributingGuides/STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function populateShortcutModal(shouldShowAdvancedShortcuts) {
```

## Destructuring
JavaScript destructuring is convenient and fun, but we should avoid using it in situations where it reduces code clarity. Here are some general guidelines on destructuring.
We should avoid using object destructuring in situations where it reduces code clarity. Here are some general guidelines on destructuring.

**General Guidelines**

Expand All @@ -210,30 +210,28 @@ const {name, accountID, email} = data;

**React Components**

Don't destructure props or state. It makes the source of a given variable unclear. This guideline helps us quickly know which variables are from props, state, or from some other scope.
Always use destructuring to get prop values. Destructuring is necessary to assign default values to props.

```javascript
// Bad
const {userData} = props;
const {firstName, lastName} = state;
...

// Bad
function UserInfo({name, email}) {
function UserInfo(props) {
return (
<View>
<Text>Name: {name}</Text>
<Text>Email: {email}</Text>
<Text>Name: {props.name}</Text>
<Text>Email: {props.email}</Text>
</View>
);
}

UserInfo.defaultProps = {
name: 'anonymous';
}

// Good
function UserInfo(props) {
function UserInfo({ name = 'anonymous', email }) {
return (
<View>
<Text>Name: {props.name}</Text>
<Text>Email: {props.email}</Text>
<Text>Name: {name}</Text>
<Text>Email: {email}</Text>
</View>
);
}
Expand Down