GoogleChromeLabs / GoogleChromeLabs/react-adaptive-hooks

Code styling

Open
#37 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.2k
Forks
112
PR merge metrics
No merged PRs in 30d

Description

As of now, the code is very verbose and easy to read but I'm wondering if we can optimize readability by tweaking some code styles and namings to prevent double negatives.

For example, the following code...
```javascript
let unsupported;

const useSaveData = (initialSaveDataStatus = null) => {
if ('connection' in navigator && 'saveData' in navigator.connection) {
unsupported = false;
} else {
unsupported = true;
}

return {
unsupported,
saveData: unsupported
? initialSaveDataStatus
: navigator.connection.saveData === true
};
};

export { useSaveData };
```

could become...

```javascript
const useSaveData = (initialSaveDataStatus = null) => {
const supported = ('connection' in navigator && 'saveData' in navigator.connection)

return {
unsupported: !supported,
saveData: supported
? navigator.connection.saveData === true
: initialSaveDataStatus
};
};

export { useSaveData };
```

maybe even use a `supported` property in the return value, I'm not sure if it's deliberate that we use negative naming for this.

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.