I've put together for you an entire visual cheatsheet of all of the concepts and skills you need to master React in 2020.
But don't let the label ...
For further actions, you may consider blocking this person and/or reporting abuse
Hi, great article. Thank you for your effort. You say list and keys section "use array element index for key" but this is not a good idea. Because when you use an index of an array as a key, React will optimize and not render as expected and also it is an anti-pattern. I just wanted to specify. Have a nice day.
As long as you do not reorder or delete any items, indexes are ok. It's ok even if you add items to the end, or always delete the last one.
Yes, you are right. It can only be missed on a large-scale project. So I wanted to specify.
I mention that a unique id is better.
Ok. I must have missed. Thank you.
You put a lot of work into this. Kudos. However this description misses a key point...
The main goal of useCallback is so child components won't re-render unnecessarily. If you create a new function on every render, and pass it as a 'callback' to a child component, that child will always re-render because it receives a different prop each time. This is why the hook is named use-callback.
Child components are not the only time when you will use useCallback. This applies to local functions used within the same component. For example, those used in the useEffect hook.
This is evident if you are using a local function within useEffect and don't include it within the dependencies array. If you're using the eslint plugin for React hooks, you'll get a linting warning which tells you to: 'move the function inside the effect, or wrap it with useCallback.'
I'm highlighting how hooks are used in practice based off of experience, not merely quoting the documentation.
True, but it is a primary use for the hook, which was not mentioned at all, which is why I pointed it out.
The useCallback hook is memoization. Overusing memoization can actually slow code because it's more time-consuming to process than to regenerate simple functions. It often adds complexity with no meaningful benefit.
The scenario you describe should occur only rarely in good code. It is more often a sign of premature optimization when every function is wrapped in useCallback. But how to decide when to or not to? For a good primer I suggest:
kentcdodds.com/blog/usememo-and-us...
Again, Kudos for taking time to share. However it's good to also grok why documented recommendations are what they are.
I'm a project lead with 30 years experience. I train and mentor devs daily on JavaScript, React, and all things code. I still try to learn something new every day though.
I'm not going to have a discussion about what you think should be emphasized. Everything I mentioned is correct. This is just a quick cheatsheet. They're not supposed to include everything.
Think about others before you comment, please. If you have a suggestion for me, fine. You can send me a message directly and we can talk about it, but there's no need to clutter up what is a cheatsheet for beginners with multiple paragraphs worth of opinions about how the article should be written.
Hi Reed,
Thanks very much for the article (and entire series), it's a great hooks-first treatment for learning React now. I'm just about to embark on my first React project but have pretty extensive experience in other languages and all the way down to the metal in terms of assembly coding. React is quite a different paradigm to what I'm used to but I'm really interested and excited by it.
The useCallback description did have me scratching my head - I really couldn't see how the performance hit of defining (not calling) an inline function would be that bad in your example when that component re-renders - the rest of the code uses arrow functions a lot which is basically short-hand for the same thing after all.
Kevin's comment did really clear things up for me - I can absolutely see a performance issue when wanting to pass on a callback as a prop to a child component, and how useCallback can therefore prevent those children from re-rendering. The name also makes more sense in that context.
I don't want to add to unnecessary clutter but wanted to add my perspective as someone with coding experience but new to React, and thank Kevin for clearing up the one aspect that was confusing me in the post.
Looks like a very welcoming and nicely done Series to get started! (Just found out about it.)
In case somebody is wondering how some things work with react and typescript:
Cheatsheets for experienced React developers getting started with TypeScript
React+TypeScript Cheatsheets
Cheatsheets for experienced React developers getting started with TypeScript
Web docs | 中文翻译 | Español | Contribute! | Ask!
All React + TypeScript Cheatsheets
is a well maintained reference point.
Finally a proper contender to take down Simon Holdorf from the Infinity Top's throne ;)
Hi Reed, thank you for the cheatsheet. I found an error in Mouse Tracker example.
This code will not remove
mousemovehandler:Here is a life example. After you press 'Toggle mouse tracker' you'll see an error in console. It happens because you should provide a reference to the handler that you want unsubscribe from. So here is the valid example.
You're right, we need a reference to the same function. That was my original code, but I removed the reference mistakenly because I thought the abstraction of the callback to handleMouseMove was unneeded. It's fixed now. Thanks Dmitriy!
There's still a comment at the end of that example that dates from the original version too.
Both
dev.toand your Blogs these line is okayreturn <div>I am learning {language}</div>;but pdf cheatsheet should update, because of closing tags!awesome pocket guide - react cheat-sheet. gearing up for react journey :-)
Nice post! I've shared ot with my colleagures who are still beginners in React.
However, I would like to say that the PDF is missing something really important: Syntax highlighting (as the post itself has). It's kind of exhausting looking at pieces of code of the same color and the less experienced people would thank having it.
Hi Eric,
Thank you!
I update the cheatsheets I make to include syntax highlighting. I usually have to do that by hand. I like to use plain text to make sure that the code is still copyable. If I used snapshots, you would have syntax highlighting, but would have to rewrite the code yourself.
Thanks for the feedback, just wanted to provide more info in this regard.
Best,
Reed
Super useful. Couple of items that would be nice to include:
Thanks again!
If I found something subject-oriented with real-life examples and of course in a nutshell, that's will be a react cheatsheet you have been provided, moreover if I did not subscribe to Bob Ziroll Bootcamp at SCRIMBA sure I will signup for your react Bootcamp.
How do i make my react app SEO friendly ? As I've completed my front end site using create-react-app . Please help !!
In terms of meta descriptions, take a look at react-helmet.
Unpopular opinion: react-helmet is just a glorified built in portal
Amazing, thanks for putting this together!
My pleasure. Thank you, Pauline!
Awesome!
Great cheat sheet really handy !
Thank you for this guide!
Nice article! It surely helped me a lot, thank you!
{todos.map(todo => <li key={todo.id}>{todo.text}</li>)}put the missing bracket for it to work :-)
Fixed
Hi Reed
Great Article thank you so much you saved my life LOL!.
Hi, great article! It is great for me as i am currently learning React! Thank you for your effort!
Nice Post! Also have a look at Pros and Cons of ReactJS Web Application Development: aglowiditsolutions.com/blog/pros-a...
thx a lot for interesting article!
Amazing Work, thanks!
Thanks but I cannot downlead the PDF
Give this guy two trophies everybody, in case he misses one!
Well summarized!
Hey when is coming the next course one month is pass 😀?