Below are few code snippets and links that are helpful when you start developing a NodeJS application.
Ref: https://gist.github.com/gaearon/683e676101005de0add59e8bb345340c
If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:
- We define variables with
let
andconst
statements. For the purposes of the React documentation, you can consider them equivalent tovar
. - We use the
class
keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don’t need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value ofthis
in a method depends on how it is called. - We sometimes use
=>
to define “arrow functions”. They’re like regular functions, but shorter. For example,x => x * 2
is roughly equivalent tofunction(x) { return x * 2; }
. Importantly, arrow functions don’t have their ownthis
value so they’re handy when you want to preserve thethis
value from an outer method definition.
Creating a hello world app https://reactjs.org/docs/hello-world.html
Setting Up Your Editor https://facebook.github.io/create-react-app/docs/setting-up-your-editor
Converting a Function to a Class
You can convert a function component like Clock
to a class in five steps:
-
Create an ES6 class, with the same name, that extends
React.Component
. -
Add a single empty method to it called
render()
. -
Move the body of the function into the
render()
method. -
Replace
props
withthis.props
in therender()
body. - Delete the remaining empty function declaration.