New React website
reactjs.org
reactjs.org
Contrast with the official Vue.js tutorial (https://vuejs.org/v2/guide/), which goes through things step by step with normal HTML syntax.
> We hope the new site will make it easier for you all to contribute improvements as well. We look forward to working with you to improve it! [1]
This was just the first phase of them moving to the new site. They understand that the docs can be better. Maybe instead of just complaining about them, you contribute to them to make them more "noob" friendly, like you are describing.
Is that a high bar for a JS frontend framework? Serious question, as it doesn't seem that way to me. This seems analogous to saying "Django docs require you to know python" or "Postgres docs require you to understand how databases work".
It is easily the most rage-inducing programmer moment I ever had, mainly because it's so fucking stupid and the only reason it took me so long was because the actual tutorial and documentation was fucking lying to me.
Technically speaking they fixed it by now: they mention the bind-thingy under "Handling Events" in the documentation, which you randomly have to stumble upon:
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState(prevState => ({
isToggleOn: !prevState.isToggleOn
}));
}
However, the tutorial is still deceiving: constructor() {
super();
this.state = {
squares: Array(9).fill(null),
};
}
handleClick(i) {
const squares = this.state.squares.slice();
squares[i] = 'X';
this.setState({squares: squares});
}
This is fine in this specific situation because the render method uses a closure: onClick={() => this.handleClick(i)}
But this is a subtle nuance that can be an incredible pain to figure out. There is no mention of all the this-related pains in the tutorial anywhere.React documentation switched from `React.createClass` to ES6 classes because they community already did at that point, and wanted to see the more "mainstream" pattern documented. I'm sorry it wasn't obvious that there is a difference between the function call and the language syntax, but it's definitely not a change in React.
The tutorial you mention works fine because `onClick={() => this.handleClick(i)}` is an alternative way to bind methods that also works. That's what the tutorial uses because it's easier to explain React first without diving into how `this` works in ES6 classes. And you can run that code and verify it works. (Every step of the tutorial has a link with a code example.) So no, it has not been broken for a year.
We also did blog about ES6 class support: https://reactjs.org/blog/2015/01/27/react-v0.13.0-beta-1.htm...
And autobinding of `React.createClass` (which you can still use—it's just in a separate package) is also still documented: https://reactjs.org/docs/react-without-es6.html
That said I'm sorry about your bad experience.
> We also did blog about ES6 class support
Not everyone reads blogs all the time. If a new product is released, it's reasonable to expect the documentation to mention the breaking changes.
React.createClass() always did (and still does) autobinding.
ES6 classes never supported autobinding.
We couldn't have changed your code from one to the other. There is no "release notes" associated with that change—changing the syntax was a conscious decision you made either when converting or when writing a new components.
It can be nearly impossible to Google something if you don't even know what it is that you don't know.
There's a comment by, well, YOU, from March this year[0] on a github issue discussing improvements to documentation, suggesting it is one of the most common troubleshooting issues, so I'm not the only idiot failing to grasp this when first diving into webdev.
It would help tremendously if there was even just a simple sentence in the tutorial like:
> "By the way, we are using an arrow function here because JavaScript has some subtle behaviour when it comes to this, but explaining the details of that here would take too long. See [here], [here] and [here]"
.. with a few links explaining both this and ES6 classes in more detail. Because otherwise you can easily get stuck not even knowing where to look for the cause of the bug.
[0] https://github.com/facebook/react/issues/8060#issuecomment-2...
That you've written so much indicates to me that you expect other people (like a framework's documentation) to introduce you to every language idiosyncrasy in any place you happen to be reading.
That's not what I want people to expect from me as a professional. People should be able to expect me to credentialize in the domain at hand.
onClick = {this.handleClick}
This is due to the way "this" is scoped in JS.
Dan mentions that it works fine if you instead do: onClick = {() => this.handleClick()}
This is using the new ES6 arrow functions which fix the "this" scoping problem.
Another alternative is to use bind() inside the onClick and set "this" to the correct value that you want.
onClick = {this.handleClick.bind(this)}
It's true that we assume preexisting JS knowledge, but your other point about how it doesn't give much insight into using React is one I haven't heard before. Can you say more about what you mean?
Anecdotally in my experience, most people seem to find the tutorial pretty helpful, but we can think about more options. Maybe there's space to add one that assumes less about JS. (And really -- thank you for complaining about this, or else we wouldn't have known.)
I feel like React expects me to have a deep knowledge of JS build tooling when all I care about getting started is building a page locally that works and does cool things.
FWIW this is how Vue's tutorial starts - and another really nice thing they do is teach you the API by entering things into your console on their tutorial page full of components.
I don't really know if this is constructive or useful, I hope it is - I just feel like React expects a lot of new users in a way it didn't used to.
https://reactjs.org/tutorial/tutorial.html#how-to-follow-alo...
Similarly, the installation page offers you to either download a single HTML file, or to install a CLI that gives you a project that's ready to go: https://reactjs.org/docs/installation.html
Could you clarify what give you an impression that you need to have a deep knowledge of build tooling to follow along?
I'll try to clarify. If you don't mind another comparison to Vue, their equivalent page: https://vuejs.org/v2/guide/ says "Or, you can create an index.html file and include Vue with: <script src="https://unpkg.com/vue"></script>", while your get started page says "If you’d rather use a local development environment, check out the Installation page." I know, if I click there it'll say I have an index.html and I know I shouldn't do it that way, but if I have none of the infrastructure on my computer and I want to build my thing on my computer, I'm looking for the script - not installation instructions.
On that 'how to follow along' page, under prerequisites it says "Note that we’re also using some features from ES6, a recent version of JavaScript. In this tutorial, we’re using arrow functions, classes, let, and const statements. You can use Babel REPL to check what ES6 code compiles to.". If this was the first React tutorial I ever looked at I'd be completely lost here and concluding I don't understand the prerequisites. If I know anything about 'relatively new' things in Javascript or Babel then I assume that I'm expected to use it somehow to actually use those relatively new things in my browser, but I have no idea how.
Also, scrolling down a bit, "if you prefer to write code in your editor" is a list of 6 steps, one of which is installing Node and another is "Follow the installation instructions to create a new project." I might not need deep knowledge, but this feels like a lot of stuff to do to follow a tutorial in my editor.
Here's my story about the old, do-it-all-locally tutorial: I'd just started an internship, and got a brief about doing some dynamic UI generation from schemas in .net stuff I'd never used, and was meant to be designing a schema to use. I had no idea what that should look like, so I learned React with your old tutorial and within a few hours could iterate on a schema to build UI components like theirs in the browser. This was amazingly helpful to me, and looked way more impressive than it actually was when I showed the boss! I just doubt that I'd do that based on your current tutorial, because I'd be on a Windows machine and get hung up installing NPM or something silly.. and that feels like a shame to me.
We do offer an HTML file to download that you can tinker with, but only on "Installation" page rather than the Tutorial. Maybe we can unify them somehow.
Overall, it's frustrating that people tell us about these issues once a year when we release something, instead of raising an issue and discussing it there. :-) If somebody told us on GitHub this is a problem, we would have fixed it a long time ago.
I appreciate that frustration, I didn't raise this as a Github issue because it didn't feel actionable and I don't want to spam all your maintainers with a complaint without having something more concrete to suggest. I'll try to put something together though if that'd be useful :)
I agree though that there is a niche for the other kind of tutorial you're describing. :-)
That shouldn't be its purpose.
Full pull request is here: https://github.com/facebook/react/pull/8848
As a result one of the React contributors ended up apologizing to react-router https://github.com/facebook/react/pull/8848#issuecomment-285...
EDIT: missing the "NOT" in my opening sentence.
https://news.ycombinator.com/item?id=15367480
(I think people didn't get it.)
Good job, fantastic. Don't let the parent complainer get you down, you really nailed it. There's a reason everyone uses React and you're a large part of that reason. Kudos.
I know most of that isn't really react's responsibility. It just happens to inhabit this sort of central position within today's JS that people look at it for guidance.
I'll be stoned here at HN for saying this, but I always considered Rails to be the high-water mark in terms of standardisation: with some experience, you could join any project and were already familiar with the folder structure and many other conventions.
I think there's something like a "React Starter Pack" project now that seems to do exactly what I was looking for last year: a set of known-good components, (pre-)configured, tested, and with the virtual stamp of approval from people who know more than me.
CRA helps with getting started by providing an opinionated build setup, but leaves the entire rest of the application structure up to you. Sounds like you're looking for something more on top of that.
I think I vaguely tossed out an idea of "CRA templates" on Twitter not too long ago, where maybe in addition to telling CRA what version of `react-scripts` you want to use, you could also give it a template package name. That way, you could specify something like `--template simple-react-redux` or `--template my-react-router-semantic-ui-setup` or something.
There's actually a pretty similar issue with Redux too (and I say that as a Redux maintainer). I opened up an issue a while back to get ideas for what a better starting experience with Redux might look like: https://github.com/reactjs/redux/issues/2295 .
JS includes _a lot_ of people, of all levels. You don't really have much choice but to do the lowest common denominators (people newer to it probably consist of the majority right now).
When I went through the VueJS stuff originally, I had a feel of "Come on, get to the point already" as I went through pages over pages to get the whole idea.
When I learnt React (originally when it came out), I looked at the first page, went quickly over the element creation (I was anti-jsx at the time. Times long gone, haha) and lifecycle hooks in like 5 minutes, went "Okay, got it. I already know how this works" and built an app.
Obviously my situation is not the common one, so doc like VueJS should be standard...but having a good "tl;dr" is critical (maybe it is in there, I didn't look, but when I learnt Vue's basic, by the time I went through most of the pages looking for a tl;dr, I had found everything else)
Writing static content is basically like building a normal website with a nice templating system. Dynamic content is simply React components that I'm use to working with on complex applications.
Easy to build, easy to deploy, and easy to change.
I had to abandon it for a project that was generating static SEO pages, it was something on the order of 2000 pages and Gatsby couldn't handle it. Hopefully they resolve that soon!
Or, hopefully, they don't. SEO pages suck users time.
I abandoned my own React-based SSG because it was slow, but I'm hoping to dust it off when I have some more time to see the effects.
Searching for a static site generator that uses React, I found Phenomic first then Gatsby. I was already leaning towards Gatsby since Phenomic is still in alpha. Now that Facebook is using it, my decision is easy. Phenomic looks like it can do a lot more than Gatsby, so maybe I'll give it a second chance in the future.
Also this is the source for the website: https://github.com/facebook/react/blob/master/www/package.js...
Does this mean the HTML is constructed by rendering components to strings using ReactDOMServer, or that the frontend scripts use React? Or both?
Gatsby is an attempt to blend the best aspects of static site generators and web apps.
...and yet, I go and try to use Facebook, and the experience is totally fucking repellent.
Even in a closed third-party testing loop, when you control for social variables and human factors, by populating your circle with only fake test accounts you control and have created yourself, for which no one else has the password. (e.g. staging a hypothetical sequence of events, to model an expected experience)
Just trying to do anything is met with the most bizarre and byzantine behaviors and switcheroos.
Nevermind whether or not one agrees or disagrees with the all-encompassing nature of Facebook's grip on so many social circles, or whether one has an opinion about Facebook's policies and business practices, the website itself is pretty bad. Bad enough that, had I my druthers, I'd be able to create something that out-competes it, if a creation I put forward could clear the sheer gravitational inertia of the network effect that Facebook enjoys. And I realize that's no small claim, but here I am making it anyway.
It's not your fault, specifically that shit sucks on Facebook all over, and I sincerely doubt you'd have the clout necessary to enact change.
Since it'd be a lot to write up, and this is simply yet another peanut gallery web forum, I'll say this much: as a user, I am clueless about the decision tree I'm offered when I log into Facebook, furthermore, so much of Facebook is mystery meat links and who knows why I see half of any of it. Then as soon as a snippet of user-created content appears, it's buried. Go in to check the settings to see what the hell this system is trying to do for me, and I see trashy icons leading to incomplete features that don't even work as advertised, and I never get what I want, when used as directed. After about 30 some-odd clicks per any given session, and maybe 100 sessions of trying and retrying various combinations from a clean cookie, learned helplessness kicks in, I shut down my computer and find something better to do.
BTW, this cuts across several assets and UI's throughout Facebook's offerings as a whole, for all devices.
And to return to the original subject at hand, compare Facebook (right now, today) to React's general website and documentation facelift. The comparison turns out to be surprisingly different in quality. (hint: facebook rates lower)
But secondly and more importantly, it seems bizarre to be amazed that a useful developer tool could be used to make a website that you don’t enjoy. Of course any decent developer tool could be used to make products that you enjoy as well as products you don’t enjoy.
Apart from viewing your timeline, posting a status message, commenting on posts, sending messages, and liking things -- all of which seem pretty normal in use -- what else would you do?
Anything else is probably a niche use, and not optimized (or having anyone care about it), including FB apps.
It'll go as far as giving autocompelte suggestions of people's full names, but then you click on the person you want and it gives you search results for them.
I think they did this so that when you search for a name they can show you all the other shit that the person is tagged in, but all I wanted was to get to their wall and post something.
Less charitably, by dumping you to an intermediate page and making you click again for their profile, FB gets to serve another batch of ads. And depending on what metric you measure it "increases engagement!!!" because it took me twice as long to get what I wanted.
I'm just one guy with an opinion, but I strongly disagree that Facebook is a model example of a complex website. Facebook is blessed with a money hose, that ultimately washes away so many other problems, meanwhile provided that Facebook is not a network hardware and CDN company, I'd contest that if that's what they wind up bragging about, incidentally, then that's clearly a hint that they've gotten their core offerings wrong.
Yes, Facebook started as a PHP garbage pile, and now it's got more going on, but the surface UX of Facebook remains a garbage pile, whether it's a fast garbage pile in terms of line speed, or a photo-realistic representation of a virtual garbage pile.
If I can get consistent browsing results, productive interactions, and notice a presentable style and appearance on a React documentation website, which is a wholly-owned property of Facebook, then why isn't the flagship Facebook system provided to end-users with the same nuanced attention to detail?
Gatsby generates HTML pages for each page so it loads as fast or faster than other static site generators but is way faster when clicking around the site as it prefetches pages and renders them in the client so the site feels like a local or native app.
It's also fully setup for building with leading modern web development tools like React, webpack, all CSS options including css-in-js, code splitting, PWA techniques, etc. so the development experience is excellent and you get production quality code without any setup.
Gatsby's ambitions are much higher than simply transforming markdown into HTML. See the writeup of the talk I gave recently describing Gatsby as a website compiler https://www.gatsbyjs.org/blog/2017-09-13-why-is-gatsby-so-fa...
DOMException [SecurityError:"The operation is insecure." Code 18: location: https://reactjs.org/commons-f40206259909ee9b7a40.js:4]`I haven't used TypeKit in a while, but it looks like they had this issue a year ago [1]. Unclear if it has been fixed or what. A lot of people I know simply embed the font in the page (ugh)
[1] https://blog.typekit.com/2016/06/03/regarding-the-flash-of-u...
this.handleChange = this.handleChange.bind(this)
example over the simpler lexical declaration. handleChange = () => {}
Is the reason for them not using the latter due to the spec not being finalized yet?React feels so much nicer and it's use of Vanilla JS makes it so much easier to debug. It's a breath of fresh air.
this.handleChange = this.handleChange.bind(this);https://github.com/tc39/proposal-class-fields
Changes to the language take time, but then they benefit everyone and not just a particular library.
--- quote ---
With the ESnext field declarations proposal, the above example can be written as
class Counter extends HTMLElement {
x = 0;
clicked() {
this.x++;
window.requestAnimationFrame(this.render.bind(this));
}
constructor() {
super();
this.onclick = this.clicked.bind(this);
}
connectedCallback() { this.render(); }
render() {
this.textContent = this.x.toString();
}
}
window.customElements.define('num-counter', Counter);
--- end quote ---this.onclick = this.clicked.bind(this); etc. are all still there
class Foo extends Component {
state = {
foo: '',
};
// The arrow function here is what you're looking for.
onChange = ({ target }) => {
this.setState({
// You can of course use `foo` directly as the key if you just have the one input.
[target.name]: target.value,
});
};
render () {
return <input type="text" name="foo" value={this.state.foo.value} onChange={this.onChange} />;
}
}Also, your example is not equivalent to either the complaint in the original comment or to the code snippet I quoted
Also: React has been binding event handlers to `this` since forever without presets (update: only in React.creatClass though)
Yes, with public fields you can write
handleClick = () => {
// ...
}
and it works like if you bound it in the constructor.Hope this helps.
handleClick = () => {...}
This is a shitty workaround that abuses class fields and arrow functionsIn fact, if you go to reactjs.org, within the first 7 seconds you can see live examples. (By scrolling down.) If you click the prominent "get started" button prominent at the top of the page, you get taken to a page that says "The easiest way to get started with React is to use this Hello World example code on CodePen" and a single click gets you there. The intro tutorial itself quickly walks you through everything, gearing up from basics to an advanced summary quickly in a well-structured way. It has a "help I'm stuck!" section that tells you exactly what you need to do if you are stuck.
This needs to die.
Someone needs to go about writing some half-assed documentation and putting it up on github without any usable links.
Information is meant to be hidden, and the role of documentation, such as reactjs.org, is properly to hide the nuggets of usable information among false starts, unexplained terminology, long flowing paragraphs of flowery prose that reduce to "", important notes that can only affect people who already know everything else about the thing in question, such as information about upgrades and transitions, and just generally give the sort of impression you get when you read through useless government paperwork.
Take note, people. if you make a site like this, then you can end up being the best-adopted and most popular solution in your entire industry - that's no way to program. Documentation is meant to be a hurdle, a kind of euthanasia program that takes enthusiastic new visitors and tears out their enthusiasm, destroys their will to live, and grinds them down with prose.