9 ms·
How Does setState Know What to Do?
- TheAceOfHearts 8y agoFYI, this is Dan Abramov's blog. He's one of the developers working on the React team. I'd highly suggest checking out his other posts if you use React, they're all superb.
- kaycebasques 8y agoI do the DevRel* for Chrome DevTools. Dan is remarkably good at DevRel. I've pinged him on a few occasions, and to my recollection he's always replied very promptly, always with a helpful answer. My impression is that he's like that with anyone who has a reasonably well-thought-out question. Which, if true, is amazing considering the size of the React community. Aside from React's own merits, I would wager that Dan's DevRel superpowers have been a non-trivial factor in React's success. * Developer relations, on the off chance anyone is unfamiliar with the term. A DevRel team for a developer product like React would be in charge of communicating new features, changes, best practices, etc. to the React developer community, answering technical questions on how to use React, and relaying community feedback to the React team.
- franciscop 8y agoI just learned that DevRel is a thing, I just thought it is a non-trivial part of a normal project but not that it was categorized separately (or I'd call it tech advocate). Not only that, I think that DevRel is the best indicator of success of any project! Basic design, documentation, etc are needed, but once those are covered it's DevRel what sets projects success apart. Famous DevRel I know and what they've been promoting to great success: - Dan Abramov, Redux and React. - Evan You, Vue.js - Lea Verou, Prism, Bliss and CSS in general. - "@dhh", Ruby on Rails. - Sindre Sorhus, npm and indie JS. Note: I just say they have greatly helped to the success, no that these are their projects. On the other hand, we all know some projects that succeed despite their founders being really bad at DevRel... but those are so rare and basically just put a lot of efforts in something related but not the same (marketing, first to the market, 10x better technically, etc). My main focus right now is learning how to get better at this since I'd love to do OSS fulltime. Any tip on how to get there would be greatly appreciated. I'm trying to learn mainly from Dan and Evan since IMHO they are next-level in this specific area :) PS, since you work for Chrome DevTools, I imagine you are in Google. I think, besides the issues of Angular 1->2, the real reason Angular stayed behind is that there were no highly visible DevRels.
- danabramov 8y agoFWIW my job role is just software developer. I try to help people because I like being a part of the community and like explaining things to others that somebody explained to me. But I’m not officially a DevRel. Although I guess I fit the shoes.
- jsjohnst 8y ago> But I’m not officially a DevRel. Although I guess I fit the shoes. Those are usually the best DevRel folks imho. Love the work you do!
- kaycebasques 8y agoRight, didn’t mean to imply that you only did DevRel. I think most React users know that you’re on the core team. Just wanted to suggest to the general HN community that your consistent efforts around helping the React community might be a factor of React’s success. Whenever there’s a post here on HN about why framework A is a success whereas framework B is a flop, the focus is usually on technical factors or developer ergonomics.
- emilsedgh 8y ago- RhodiumToad on Postgres
- mcintyre1994 8y agoTaylor Otwell with Laravel definitely fits this category too.
- sorahn 8y agoIs there any way (other than the chrome bug tracker) for devs to talk to you guys about Dev tool bugs, or suggestions? There are definitely some lingering low pri bugs in the issue tracker that would improve the QoL that would really help the dev tools experience. Example: https://bugs.chromium.org/p/chromium/issues/detail?id=771144 https://bugs.chromium.org/p/chromium/issues/detail?id=771144 This happens every time. So I just stopped moving the tabs, but if the dev tools are not wide enough to show the (ever increasing) number of tabs, it’s always the 3rd party ones that get pushed off.
- bostonvaulter2 8y agoI would LOVE if this was fixed in Chrome.
- scumblr 8y agoI love getting the inside view. Dan's asides about how the team decided to use this or that approach are priceless.
- max23_ 8y agoNever knew he started a blog until recently when someone posted his blog post on how React tell a class from a function. Good stuff if you want to know how React work internally.
- eddyerburgh 8y agoThat's because he only started it recently. His first post was November 30 this year, and he already has 5 high-quality articles!
- flowerlad 8y agoReact is a bit less hot today than it was a few weeks ago. What changed is that FireFox released support for Shadow DOM. Also Microsoft is moving to Chromium. Which means Shadow DOM is suddenly hot and technologies that don’t support Shadow DOM, including React, became a bit cold.
- gbear605 8y agoNo technology becomes more/less hot in a period of a couple weeks, not even JS frameworks.
- taeric 8y agoI want to believe this. However, I also feel bewildered when I check the news of what all has happened in js frameworks in the past 3 years. Especially true, if I consider how different the big frameworks of today are, compared to the same frameworks 2 years ago.
- Vinnl 8y agoReally, if you're talking three years ago, React was already widespread. The main change is that Angular.js back then was still widespread as well, and that Vue wasn't really. Sure, things have changed (e.g. TypeScript is far more accessible today), but if you've been doing React for the past few years, the changes haven't been that drastic, and primarily for the better (e.g. Create React App, that mainly allowed you to forget things, rather than having to learn new things).
- tuesdayrain 8y agoA technology could become cold in an instant if a superior solution was found. I don't think that's true with React though
- gbear605 8y agoAny actually used technology won't become cold instantly because old systems will already depend on it and won't be rewritten immediately
- deleted 8y ago[deleted]
- Jasmine97 8y agoGreat Stuff
- larkinrichards 8y agoDoesn’t answer the question.
- InGodsName 8y agoThose working on projects. What do you prefer? Should i choose React or Vue?
- Siilwyn 8y agoThis is very much personal preference. I would suggest to look at their docs & create something small for both. Plus try out their 'standard frameworks': Nuxt & Next.js.
- sametmax 8y agoTry both, and see which one you prefer. Vue first though, as it's easier to get started with it and it will get a sense of what minimal setup you should expect. Then try to match that with react. If you start by following most react tutorials, they will make you begin with something way more complicated that it needs to be and you will get discouragedd. Both have a "cli" tool. Everybody tell you to start with it. I strongly advise against it, as it's the best way to not understand a thing about what you are doing and make bad decisions. Find a tutorial that starts with the bare lib (no webpack, no transpilation, nothing but a script tag), for both vue and react. Then when you know how this work, find a minimal webpack based tutorial. Then when you know those basics, use the cli tool, but immediatly use the eject feature. Read the result to understand the whole shebang. Once you have done that, you can start any project using the cli without eject, and be confident you know what's going on. It will make you not only very productive, but also will let you take decision based on what you know, and not what other people wants you to know. Now, I personnaly prefer Vue as I find the lib easier to work with, the community saner and the documentation is one of the best I've read, even including non JS projects. But again, make an educated choice.
- parhamn 8y ago> If you start by following most react tutorials, they will make you begin with something way more complicated that it needs to be and you will get discouraged. Can't agree more with this. There are quite a few reasons I think those starter-kits and tutorials are very harmful especially to new developers. Figuring out how your tsconfig/webpack/babelrcs/state-handlers/etc all fit together should be something that should certainly be done and learned incrementally. Perhaps the issue is the amount of boilerplate you need to start a simple app. There should be a flask[1] like starter for react/vue apps. Parcel seems like the closest thing but its still not obvious to me why they demo 4 files to get started [2] -- we already dynamically transforming and compiling everything why not just have a single `index.js` with a Index/Main entrypoint? Is there anything out there to do something as simple as: import * as React from "react" import {Html, Body, Title} from "parcel" const Index = () => { return ( <Html> <Title>MySite</Title> <Body> <h1>Hello world!</h1> </Body> </Html> ) } with a `cmd {run,build} index.{jsx,tsx}` [1] https://github.com/pallets/flask/#a-simple-example https://github.com/pallets/flask/#a-simple-example [2] https://parceljs.org https://parceljs.org
- rojappriya 8y agoGiven so much info in it, The list of your blogs are very helpful for those who want to learn more interesting facts. Keeps the users interest in the website, and keep on sharing more Please free to call us @ +91 9884412301 / 9600112302 More Details: https://www.credosystemz.com/courses/openstack-training-chennai/ https://www.credosystemz.com/courses/openstack-training-chen...
- Raed667 8y agoI love these posts but despite the warning I'm sure some of the things here will end-up in React junior positions interviews.
- inglor 8y ago״However, this has always led to obscure bugs so Hooks force you to solve the package duplication before it costs you." So basically the fact hooks doesn't support multiple react instances isn't a but but a feature :D?
- jcutrell 8y agoMore like "this tool wasn't designed to work that way, so to use this part of the tool, you'll have to conform to the way it was intended to be used."
- sfvisser 8y ago> But as we have seen today, the base class setState() implementation has been an illusion all along. It doesn’t do anything except forwarding the call to the current renderer. And useState Hook does exactly the same thing. This is worded a bit weirdly. The fact that there is some indirection and the meat of the `setState` is in the renderer and not in the component doesn't really make `setState` an illusion. A call to `setState` still does exactly what we thought it did.
- maaaats 8y ago> > And useState Hook does exactly the same thing. Except it does more bookkeeping behind the scenes to know which state you want (since you're not passing in an identificator). Wonder why they chose that solution, as it's just more magic for really no gain, and it will give you funny bugs if you call it in a loop or in a condition.
- danabramov 8y agoI wrote about why here: https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889 https://medium.com/@dan_abramov/making-sense-of-react-hooks-... (TLDR: that makes custom Hooks very powerful)
- petilon 8y agoFrom hooks documentation: If you look at a typical React application in React DevTools, you will likely find a “wrapper hell” of components surrounded by layers of providers, consumers, higher-order components, render props, and other abstractions. React applications using the MVC model don't have this problem. In MVC Components just handle rendering. Stateful logic go into controllers. I think React is getting unnecessarily complicated because of the "everything is a component" model. I strongly recommend comparing/contrasting this with MVC model. Here's an MVC router that works well with React: https://github.com/edman3d/mvc-router https://github.com/edman3d/mvc-router It is a pity that React was originally designed to be the V in MVC, and then the developer community took it in a different direction.
- HugoDaniel 8y agoThese posts are cool. I'm planning on writing a set of react interview questions based on them.
- vanderZwan 8y agoGiven this disclaimer at the top of every article, that sounds a bit inappropriate: > Disclaimer: Just like most other posts on this blog, you don’t actually need to know any of that to be productive with React. This post is for those who like to see what’s behind the curtain. Completely optional!
- HugoDaniel 8y agoI only want my team to be composed of those who like to see what's behind the curtain.
- deleted 8y ago[deleted]
- aerovistae 8y agoEveryone knows the best teams are homogeneous, and everyone knows that if a candidate hasn't looked behind the curtain of React, then they probably don't look behind the curtains of anything.
- ken 8y agoThere's dozens of layers of curtains, and nobody has this level of expertise at all of them. Have you read and understood all of tcp.c? Can we quiz you on the USB protocol?
- smackfu 8y agoWouldn't you just be testing if they read the blog posts?
- pomber 8y agoThis is from the second post: > Just like in my previous post, you don’t need to know this to be productive in React. I didn’t know this for years. Please don’t turn this into an interview question. In fact, this post is more about JavaScript than it is about React. https://overreacted.io/how-does-react-tell-a-class-from-a-function/ https://overreacted.io/how-does-react-tell-a-class-from-a-fu...