c-hive / dotdev

Next.js SPA professional website template for teams and individuals: https://c-hive.github.io/dotdev/
MIT License
0 stars 1 forks source link

Improve conditionals to avoid code littering #105

Open gomorizsolt opened 4 years ago

gomorizsolt commented 4 years ago

(1) Instead of inline if conditions: https://github.com/c-hive/dotdev/blob/e1fd40f11bbdad8f8bb44a5ecb06b170236108a3/src/components/Header/Header.js#L39

Use the && operator consistently(IIRC we already discussed this):

{settings.logo && <Logo src={settings.logo} alt={settings.name} />}

(2) Instead of && to ensure object fields: https://github.com/c-hive/dotdev/blob/e1fd40f11bbdad8f8bb44a5ecb06b170236108a3/src/components/Header/Header.js#L42

Use the optional chaining operator:

{settings?.header?.technologies && ( ... )}

We may also find further improvements.

thisismydesign commented 4 years ago

Feel free to do these small refactors when you notice them.

gomorizsolt commented 4 years ago

https://github.com/zeit/next.js/releases/tag/v9.2.0

Use optional chaining syntax: #9975

Cool! The underlying framework supports the optional chaining operator out of the box. My gut feeling, though, is that we must tweak the linter config to make it work.