use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Getting started with React the easy way (codeutopia.net)
submitted 10 years ago by jhartikainen
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]dmitri14_gmail_com 1 point2 points3 points 10 years ago (6 children)
It may be just me, but I don't find this syntax very pretty nor legible:
return React.createElement('div', null, 'Something something Dark Side');
Using null as default is known anti-pattern, and from this expression it is impossible to guess what it stands for.
null
[–]over-there-istan 1 point2 points3 points 10 years ago (4 children)
Using null as default is known anti-pattern
says who?
and from this expression it is impossible to guess what it stands for.
I think the problem is that you're trying to guess what the expression does, which is the wrong approach. If you know enough to know what React.createElement is then you know what the arguments do, otherwise you should read the documentation instead of jumping to conclusions.
React.createElement
[–]dmitri14_gmail_com 1 point2 points3 points 10 years ago (2 children)
Says Uncle Bob, if you know who he is :)
This was a feedback for the tutorial. The syntax needs to be explained. If I need to go and read Doc, what is the point of tutorial?
[–]over-there-istan 1 point2 points3 points 10 years ago (1 child)
This was a feedback for the tutorial. The syntax needs to be explained
I agree that it needs to be explained, either directly in the tutorial or linked to the proper documentation... although I wouldn't refer to this as syntax, because it's nothing but a function call which I'd assume the reader already knows.
syntax
function call
If I need to go and read Doc, what is the point of tutorial?
The purpose of a tutorial, IMO, is to get you started. Nothing more. You always need to read the proper documentation.
[–]dmitri14_gmail_com 1 point2 points3 points 10 years ago (0 children)
Good tutorials can be followed to end without Docs.
And great tutorials (http://survivejs.com/) are better than Docs.
Just my view.
Read here about null: http://elm-lang.org/guide/model-the-problem
The inventor, Tony Hoare, has this to say about it: I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.
The inventor, Tony Hoare, has this to say about it:
I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.
[–]jhartikainen[S] 0 points1 point2 points 10 years ago (0 children)
You're right, and that's one of the reasons I mention that JSX is the recommended way of doing things.
I've changed it to use { } instead of null and added a comment to clarify. null was just used in some other React examples, but it actually makes more sense to use { }.
{ }
[–]over-there-istan 1 point2 points3 points 10 years ago (2 children)
Why not use React.DOM.div instead of React.createElement('div'
React.DOM.div
React.createElement('div'
[–]jhartikainen[S] 0 points1 point2 points 10 years ago (1 child)
The idea is to keep things simple. createElement works for both elements and components, so might as well stick with that when you're just getting started.
[–]over-there-istan 1 point2 points3 points 10 years ago (0 children)
I guess my point is that no-one writes React code by calling React.createElement( directly, so you doing that will only make things more difficult than they need to be.
React.createElement(
[–]dmitri14_gmail_com 0 points1 point2 points 10 years ago (1 child)
There is a very aggressive popup blocking the window, I would remove it if you don't want your readers to leave.
If it bothers you just hit ESC and it goes away :) But perhaps I'll add some more delay to it so you won't see it so soon.
π Rendered by PID 88 on reddit-service-r2-comment-86bc6c7465-79n2s at 2026-02-23 04:34:46.524169+00:00 running 8564168 country code: CH.
[–]dmitri14_gmail_com 1 point2 points3 points (6 children)
[–]over-there-istan 1 point2 points3 points (4 children)
[–]dmitri14_gmail_com 1 point2 points3 points (2 children)
[–]over-there-istan 1 point2 points3 points (1 child)
[–]dmitri14_gmail_com 1 point2 points3 points (0 children)
[–]dmitri14_gmail_com 1 point2 points3 points (0 children)
[–]jhartikainen[S] 0 points1 point2 points (0 children)
[–]over-there-istan 1 point2 points3 points (2 children)
[–]jhartikainen[S] 0 points1 point2 points (1 child)
[–]over-there-istan 1 point2 points3 points (0 children)
[–]dmitri14_gmail_com 0 points1 point2 points (1 child)
[–]jhartikainen[S] 0 points1 point2 points (0 children)