DEV Community

Discussion on: 10 JavaScript concepts for React Beginners

Collapse
 
loucyx profile image
Lou Cyx

A few missing things I noticed where missing or incomplete:

  • Functions definitions: Arrow functions don't need the return keyword always, so you can write that subtract function like this:
const subscract = (num1, num2) => num1 - num2;
Enter fullscreen mode Exit fullscreen mode

And App like this:

const App = () => (
    <div className="App">
        <h1>Hello world!</h1>
    </div>
);
Enter fullscreen mode Exit fullscreen mode
  • Classes and the Extend keyword: Worth mentioning that nowadays you don't need classes for components in React (Error boundaries are the only exception, and you can still use npm dependencies to not use classes for that either).

  • Async/Await: Before learning async/await is key folks understand Promises. An example of that getPersonsInfo function without async/await to illustrate:

const getPersonsInfo = name =>
    server
        .getPeople()
        .then(person => person.name === name)
        .then(console.log)
        .catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Is also important to notice that using async functions in side effects with useEffect is far from ideal.

  • Array methods: Important resource when working with React: doesitmutate.xyz/ ... that site shows which methods change the original data and which ones don't. You should try to avoid mutations in React, so stay away from the methods that change the original data.

  • Template Literal: They are way more powerful than plain strings, because they also provide a way of using a function next to them. More info here. I use that approach in one of my libs.

  • Deconstructing: Deconstructing is quite convinient in function components, and can be done directly on the head of the function:

const Greeting = ({ name }) => <div>hello {name}</div>;
Enter fullscreen mode Exit fullscreen mode

And also is worth mentioning that you can set default values for optional properties:

const Greeting = ({ name = "world" }) => <div>hello {name}</div>;
Enter fullscreen mode Exit fullscreen mode

Also, your example has a typo when deconstructing objects.

  • Spread Operator: To concat arrays, nowadays is still faster to use Array.prototype.concat, but for stuff like copying object properties is actually really convenient.

  • Import and Export: In the export example you're missing the export keyword. And is also important to mention that you can import and export named and default, so ideally we should have 4 examples.

  • Code Hello World project with React: You mention a link to download Node, but didn't provided it. Also the command to run create-react-app is actually:

npm init react-app
Enter fullscreen mode Exit fullscreen mode

And the default app is already a "hello world" of sorts, so idk if this point makes much sense.


That's it! Cheers!

Collapse
 
sm0ke profile image
Sm0ke

Hello @lukeshiru

Ty for reading the article.
Noted all your remarks

🚀🚀

Collapse
 
sm0ke profile image
Sm0ke

Just PM you on Twitter.
🚀🚀
In case you have time for a small chat, thanks in advance.

Collapse
 
mmk2020 profile image
MMK2020

Nice article. Thanks