Velocidad de Escape

Protected routes and authorization using React Router v6

In the project I am currently working on, a specific need arose, we should protect certain routes of a web application from certain user roles (for security reasons). For example, we have a page where administrators can add and delete users, this power can only be held by us (this must be a private page). **React Router v6** (latest version), it does not offer any functionality for this type of situation, the implementation is the developer's task. My first approach to the problem was to try to build a "wrapper" for the `Route` component of React Router: ```js import { Navigate, Route }...

React

Standard built-in objects in JavaScript

> The term "global objects" (or standard built-in objects) here is not to be confused with the global object. Here, "global objects" refer to objects in the global scope. > The global object itself can be accessed using the this operator in the global scope. In fact, the global scope consists of the properties of the global object, including inherited properties, if any. <a class="hover:no-underline text-blue underline" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects#standard_objects_by_category" target="_blank" rel="noreferrer">Standard built-in...

JavaScript

Destructuring: From Zero to Hero

**Destructuring assignment** is probably one of the most importante features that came with ES6. Basically allow us unpack values from arrays, or properties from objects, into distinct variables. In older versions of ECMAScript this was a bit cumbersome: "Destructuring" arrays: ```js var myArr = ["Andres", "Bedoya"] // ES5 and previous var firstName = myArr[0] var lastName = myArr[1] // ES6 const [firstName, lastName] = myArr ``` "Destructuring" objects: ```js var myObject = { firstName: "Andres", lastName: "Bedoya" } // ES5 and previous var firstName = myObject["firsName"] var...

JavaScript

Stop using If else and Switch statements

This is quite difficult to explain, because I don't completely disagree with the use of if-else. The main reason for the existence of the switch statement was to avoid if-else structure in certain cases. Sometimes we have more than 1 comparison to do, since there could be many cases to evaluate, and at this point these statements become something tremendously verbose. ## Using if-else ```js function rating(rating) { if (rating === "five") { return "you are a super genius" } else if (rating === "four") { return "you are very smart" } else if (rating === "three") { return...

JavaScript