-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Minor README changes #1
Conversation
In my opinion, arrow syntax makes it easier to read partially because it takes less space. // easy to read
<button onClick={() => multiply(3)}>triple</button>
// more difficult to read
<button
onClick={() => {
multiply(3)
}}
>
triple
</button>
// most difficult to read
<button onClick={() => {multiply(3)}}>triple</button> This becomes exaggerated when there are many properties on a component // easy to read
<button
onClick={() => multiply(3)}
onContextMenu={() => multiply(3)}
color="blue"
>
triple
</button>
// more difficult to read
<button
onClick={() => {multiply(3)}}
onContextMenu={() => {multiply(3)}}
color="blue"
>
triple
</button>
// most difficult to read
<button
onClick={() => {
multiply(3)
}}
onContextMenu={() => {
multiply(3)
}}
color="blue"
>
triple
</button>
While I understand the sentiment, I think that the readability advantages outweigh implications. In general, functions should be tolerant to arrow function implicit return. One that is not tolerant which causes confusion is // error
useEffect(() => multiply(3))
// success
useEffect(() => {
multiply(3)
})
// success
useEffect(() => {
multiply(3)
// cleanup function
return () => {}
}) This intolerance causes many bugs and in my opinion is frustrating to orchestrate because of it. To sum it upThis topic is highly opinionated, but I think that generally speaking, we should be leveraging implicitly returned arrow functions because it nets less LOC which is one of the determining factors in how complex something is perceived to be. // less perceived complexity
const myFunction = (a, b) => a + b
// more perceived complexity
function MyFunction(a, b) {
return a + b
} |
I wouldn't use it for callbacks ( user is supposed to know what those do, and if they don't it's react's docs job ) or effects ( same ) EDIT: As you can see this is the case in the examples, I left the unambiguos calls in the short form (like onClick) |
Thanks for the review and the change suggestion. wrt Merging this. |
On second thought, I think I would change |
* Update readme.md * Restyled by prettier-markdown Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Restyled.io <[email protected]>
* fix typo * rework async part * added introduction * common preload for async read * re-read #1 * prettier & remove async old statement * added loadable utils * re-ran prettier * cleaned loadable * improve loadable intro * quick update * fixed write async atoms suspend timing * moved async * Update docs/guides/persistence.mdx Co-authored-by: Daishi Kato <[email protected]> * Update docs/guides/async.mdx Co-authored-by: Daishi Kato <[email protected]> * simplify Suspense * Update docs/guides/async.mdx Co-authored-by: Daishi Kato <[email protected]> * revert readme Co-authored-by: Daishi Kato <[email protected]>
I tried to make the README more new user friendly.
A couple of questions:
can this be written like
Or does it need the return value of set() ?
Same here, can it be rewritten with {} to make it less cryptic?
TLDR I would be careful with the short syntax for arrow functions because it can imply something that isn't necessary ( this is strictly related to the README )