DEV Community

Cover image for 10 JavaScript concepts for React Beginners

10 JavaScript concepts for React Beginners

Sm0ke on April 09, 2022

React is a Javascript frontend library and if you want to get started with React first you have to learn Javascript, the programming language that ...
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

Collapse
 
samithawijesekara profile image
Samitha Wijesekara

This is really important for the react developers. Article is clean and can understand concepts simply. Thank you for sharing. β™₯️

Collapse
 
sm0ke profile image
Sm0ke

Ty for reading Samitha.
πŸš€πŸš€

Collapse
 
crearesite profile image
WebsiteMarket

This is great, ty!

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€

Collapse
 
admindashboards profile image
admin-dashboards

Nice ..

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€

Collapse
 
bangsluke profile image
Luke Bangs

This is a really really good breakdown of the concepts and a few things have just clicked in my mind thanks to reading this. Cheers!

Collapse
 
sm0ke profile image
Sm0ke

Ty for reading @bangsluke
πŸš€πŸš€

Collapse
 
zoltanszogyenyi profile image
ZoltΓ‘n SzΕ‘gyΓ©nyi

Thanks for the article!

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€

Collapse
 
lowcodecharts profile image
MyCharts

Nice tutorial.

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€

Collapse
 
uithemes profile image
ui-themes

Really useful

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€

Collapse
 
joshuaneedham profile image
Joshua Needham

Nice overview. You have a misspelling in your subtract function example, FYI. It would also be helpful and raise some questions if you mention anonymous vs named functions. Thanks for the breakdown.

Collapse
 
sm0ke profile image
Sm0ke

Noted & ty for reading!
πŸš€πŸš€

Collapse
 
yannid profile image
Vuyani Daweti

DOMs

Collapse
 
sm0ke profile image
Sm0ke

Noted. πŸš€πŸš€

Collapse
 
kevincp17 profile image
kevincp17

Thanks dude, gonna need this in the futureπŸ‘

Collapse
 
sm0ke profile image
Sm0ke

πŸš€πŸš€