Multiple elements in React without a wrapper component

In React, each component can render only a single element. At the moment, there’s no way to return a multiple elements from a component’s render function. However, if you need to render multiple components anywhere else, here are 2 solutions. Returning Multiple Elements as an Array It’s good practice to use helper methods or functions to generate part of your component. It’s common to want to return multiple elements from your helper method without a wrapper…

Generators, Coroutines, Async/Await – The future of Javascript

This article assumes you’re already familiar with the basics of callback hell, promises, and the Javascript event loop. For the past few years, promises are rapidly becoming popular. They make it much easier to deal with complicated asynchronous code than callbacks. However, we can do better than promises. Problems with promises Promises have several issues that can make large applications difficult to understand, debug, and maintain: You can’t abort a chain of promises In this example, if we don’t want to run the rest of the promise chain, we use a throw to skip the processData

Best Javascript Frameworks: React, Redux, MobX, Vue

I often get asked “which Javascript framework should I use?” My answer is usually “it depends, but probably React.” jQuery jQuery is a Javascript library that helps you perform common tasks in Javascript. jQuery used to be extremely useful because it standardized behavior across browsers. Different browsers used to behave slightly differently; jQuery made those differences go away. Nowadays, the popular browsers all behave nearly identically, so jQuery isn’t as useful…

What is the Event Loop in Javascript

If you’ve written enough Javascript, you’ll encounter this for sure: Why wait for 0 milliseconds? Why not just call doSomething directly? The answer is that this setTimeout isn’t telling the Javascript engine to run doSomething after 0ms. Rather, it’s telling the Javascript engine to run doSomething after at least 0ms. This is a key distinction for understanding how Javascript works. doSomething could run almost immediately or it could run seconds later…

An Intro to RxJS and Observables: a General Version of Promises

Asynchronicity is arguably the hardest part of Javascript development. I’m assuming you’re already familiar with promises. If not, you can read about it and come back when you’re done. Understanding promises is crucial for modern web development. Promises and RxJS Promises solve Ajax callbacks very well. Remember the days when you had to handle multiple parallel Ajax requests with callbacks. How did you handle it if one fails? It probably wasn’t pretty…

Load jQuery from Google’s CDN in WordPress

WordPress loads jQuery from your server by default. It’s much better to load jQuery from Google’s CDN (content delivery network). Here are the 4 main reasons:
  1. Your visitors probably already have jQuery from Google’s CDN cached. This means jQuery will load nearly instantly.
  2. It’s probably faster to load jQuery from Google’s servers than your servers. They have faster servers and better networks. They also probably have a data center that’s closer to your visitor.