Posts by Luiz Felipe • 32,886 points
746 posts
-
5
votes3
answers195
viewsA: Why do I need to spend two then on AJAX requests made with the fetch API?
To API fetch returns a Promise with a Response, which contains various data relating to the response to the request, such as status, URL or the body itself (body). However, the property body of…
-
4
votes2
answers104
viewsA: Difficulty in interpreting Arrow functions that return Arrow functions in Javascript
This syntax does not imply dependency injection, it just means one function is returning another. More explicitly, what is occurring is the following: function Carregar() { return function() { }; }…
-
1
votes1
answer137
viewsA: Send Array in an input as string for javascript php
You can use the method JSON.stringify to serialize the JSON: function generateInputHTMLWithJSON(inputName, data) { const input = document.createElement('input'); input.type = 'hidden'; input.name =…
-
15
votes3
answers4946
viewsQ: What is a monorepo? What are its advantages and disadvantages?
What is a monorepo (mono repository) and what problems it seeks to solve? What are the advantages? What are the disadvantages?
software-architectureasked Luiz Felipe 32,886 -
4
votes1
answer32
viewsA: array only displays the first length using foreach
There is a serious problem of understanding in your code, as you are nesting unnecessarily, a for within a forEach. The forEach will invoke the callback passed to each member of the array, which…
javascriptanswered Luiz Felipe 32,886 -
8
votes2
answers154
viewsA: Is it possible to condition an operator += in a ternary?
Such operators as the +=, do two things: perform an arithmetic operation (in this case the addition operation), and: Assign the result of the back opration to variable. To learn more, see…
-
8
votes1
answer850
viewsA: How does the "infer" of Typescript work?
The infer is used in conjunction with type conditions in Typescript because it will try infer a type and, if not possible, something must happen. So it must always be in a conditional type.…
-
2
votes1
answer165
viewsA: Class change to function
Tipando props Like props are passed as the first parameter for functional components by React, just put the appropriate types for the first parameter. Generally, one creates a interface for that…
-
5
votes2
answers303
viewsA: How to assign the result of an object breakdown to a variable that contains all unstructured fields?
You cannot do this. By the very name of the resource - de-structuring -, you are removing, unstructured an object. There is no way to use a "disruptor" as a tool to build other objects. What you can…
-
2
votes1
answer68
viewsA: What is the advantage of using the setState() function to modify an array?
In those two cases you pointed out, nay is about what is more efficient, but what is right and what is wrong within the conventions adopted by React. To documentation states that any attempt to…
-
2
votes1
answer64
viewsA: How to use Generics with the props of a component?
Just use as a generic of normal functions, Typescript will understand that it is an React component when you call it. Thus: interface Props<T> { items: T[]; } // ↓↓↓ function…
-
5
votes2
answers61
viewsA: What is the definition of delete in Javascript?
The delete not a guy, but a operator that removes a property from an object. However, it will only work on properties that have the property attribute [[Configurable]] defined as true. Behold: const…
-
1
votes1
answer127
viewsA: Set TAB key behavior - Avascript
You can use the attribute tabindex, that defines the focus sequence on a page. See an example: input { display: block; } <input tabindex="1" /> <input tabindex="3" /> <input…
-
4
votes1
answer44
viewsA: Browsers and ES6
Most modern browsers already support Ecmascript 2015 (alias ES6) natively, in addition to later versions. However, there is no guarantee that all your users will always use browsers that support…
-
4
votes3
answers387
viewsA: Is there more than one way to use "if"?
The instruction if is usually followed by keys. However, you can omit them if you want to execute only one expression if the condition is evaluated as true: if (true) console.log(1); // 1 if (false)…
-
2
votes2
answers163
viewsA: How to tag with javascript
The method document.querySelector will return only the first element that satisfy the selector informed in the first argument. If you want to get the complete list of all elements that satisfy the…
-
5
votes1
answer71
viewsA: How do I get a function within a functional component to pick up the props of that component?
If you want to access the props of a component within a function defined within it (such as handleAdd), you don’t need to use this or even pass them as argument. You can access them normally, using…
-
9
votes1
answer237
viewsA: What is Prototype Pollution?
First of all, it is worth understanding at least what the Javascript prototypes are. Basically, every Javascript object can inherit properties and methods from prototype chain. Primitives, in turn,…
-
4
votes1
answer123
viewsA: Delete element Javascript array
Initially, nums was declared as array: let nums = []; However, in the function mostranum, you are trying to use the operator += in an array. In this case, the array will be converted to a string,…
javascriptanswered Luiz Felipe 32,886 -
3
votes4
answers292
viewsA: How to find the index of an object in a javascript list
If you want to compare for an object directly, you can do something like this: const l = [ { nome: 'João', idade: 15 }, { nome: 'Pedro', idade: 17 }, { nome: 'Felipe', idade: 12 } ]; function…
javascriptanswered Luiz Felipe 32,886 -
7
votes1
answer850
viewsQ: How does the "infer" of Typescript work?
I know it was introduced in language version 2.8 (see here), but even though I read these release notes, I still can’t understand the workings of infer. How it works? What is your real goal?…
-
1
votes2
answers34
viewsA: Reveal the Boolean value
The problem is in the following expression: valor1 > valor2 || valor1 < valor2 She will always evaluate a true, since the operators > or < do not return the largest number, but rather a…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer70
viewsA: How to access the properties of a data that is defined with type "Object" in Typescript?
According to the types definition of the library you passed, the type of the second parameter of the callback is object | undefined. This means that despite optional chaining (?.) allow you to…
-
6
votes3
answers174
viewsA: Separates letters by javascript line
Remember that your string has characters whose code-point is higher than U+FFFF, the behavior may not be as expected, see: const string = 'Olá! '; string .split('') .forEach((char) =>…
-
6
votes2
answers114
viewsA: Error converting string to numeric value
What happens is that parseFloat accepts a string in a valid numeric Javascript format. In your case, the string is invalid, since the decimal box separator is a comma. This will cause all characters…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer203
viewsA: How to use "shouldComponentUpdate" with Hooks?
In such cases, you can use the API React.memo, one Higher order Function. Of documentation: If your Function Component renders the same result given the same props, you can involve in it a call to…
-
5
votes2
answers88
viewsA: I cannot invoke a Setter or getter in Javascript
When you use the advisors get or set in Javascript, it uses the default access format or definition of the language. So, to access, you must use: obj.prop; And to define: obj.prop = "New Value";…
-
4
votes1
answer283
viewsA: What’s the difference between using a div and React.Fragment?
As you may know, the JSX is a mere syntactic sugar. It is not part of the Ecmascript specification. So, when compiled, JSX becomes something like this: React.createElement(component, props,…
-
3
votes1
answer704
viewsA: I would like to know how to go through an array within another javascript array!
In your code, you are checking whether the array complete is a string: if (usuarios.tecnologias == "css") { /* ... */ } This is incorrect because obviously a array will always be different from the…
javascriptanswered Luiz Felipe 32,886 -
4
votes1
answer82
viewsA: What’s the difference between using and not using keys in string interpolation in PHP?
According to the documentation, this call feature interprets variables within strings. But it can also be called interpolation. This is not an example of concatenation. Although they are used to…
phpanswered Luiz Felipe 32,886 -
4
votes1
answer87
viewsQ: What’s the difference between debauchery and Throttle?
I see that many people use techniques such as debauch to prevent a function from being called many times. But I also see a technique called Throttle. Ness sense, what’s the difference between…
uiasked Luiz Felipe 32,886 -
2
votes1
answer111
viewsA: Can you get Event.preventDefault() if the call has parameters?
You can pass the event as argument for the function. In Javascript attributes, event is in the scope. function handle(name, event) { console.log(name); // Luiz console.log(typeof…
-
13
votes1
answer4239
viewsA: What are the differences between Promise.all() and Promise.allSettled()?
Basically, Promise.all and Promise.allSettled are two between the so-called "promise combinators". In summary, Promise.all will return a array with the result values of all past promises. He will…
-
5
votes3
answers128
viewsA: Map with dynamic array and property
With this code you tried to use: const getProperties = (array, prop) => array.map(({ prop }) => prop); You are mapping the array from the first parameter to another array which will be formed…
-
5
votes1
answer185
viewsA: What is the difference between creating an object from the literal form or from a constructor function?
In short, the difference is in the way objects are created and therefore the constructor of objects. In your first example: let pessoa = { nome: 'Pedro' }; console.log(pessoa.nome); You are simply…
-
1
votes1
answer510
viewsA: Basic authentication request does not work
The error you are experiencing is due to the security policies of the CORS, implemented in the most modern browsers. To learn more, read this other question. Thus, you should add headers on your…
-
1
votes1
answer138
viewsA: How to open an HTML document from fetch in the same tab?
By this stretch: What I was doing before was writing the received text with the document.write, but there comes a time when it doesn’t work because the contents of the files accumulate on the page.…
-
5
votes2
answers863
viewsA: Convert binary to decimal without using "parseint()"
Your problem is that you are converting from binary to decimal "in reverse". In the binary numerical system, to convert a number to the decimal numerical system, we must, from right to left,…
-
1
votes1
answer186
viewsA: How can I inject a standard script into my HTML files using Node.js?
As placed in comments, you can use regular expressions for this. You can also, for example, edit your file and include some "special comment", which we will use to restore by the script to be…
-
2
votes1
answer393
viewsA: What is the advantage of using a Refresh Token instead of just the Access Token?
The advantage is greater security. But of course this will depend on the way you implement it. Obviously it’s not because you use two tokens that its application will magically become safer. :)…
-
6
votes1
answer63
viewsQ: What are the differences between comparison operators in Erlang?
In Erlang, we have the following comparison operators: =:= =/= == /= It is said that the latter two can be used to make comparison between integers and floats, since the first two differentiate one…
-
6
votes2
answers398
viewsQ: What are the differences between a type and interface alias in Typescript?
Typescript allows us to create aliases for types. For example: type State = 'inactive' | 'active' | 'banned'; The type allows to also create types for objects, such as: type User = { username:…
-
10
votes2
answers171
viewsQ: Besides structures like "for", "while", "goto" or recursion, is there any other way to repeat something in the programming?
In structured programming, we have structures as links for, while and similar structures, in addition to goto, that allow us to realize repetitions. In functional programming, recursion is used to…
-
3
votes2
answers74
viewsA: I cannot use a value saved in the state of React
The problem is that setState is asynchronous within Event handlers. This means that the state is being defined but cannot be accessed through this.state synchronously. There are two sessions of the…
-
3
votes1
answer2464
viewsA: How to validate objects inside objects with Yup/formik?
Just use Yup.object().shape() inside the property. Something like this: import * as Yup from 'yup'; const schema = Yup.object().shape({ user: Yup.object().shape({ email: Yup.string() .email()…
-
3
votes1
answer40
viewsA: Combine two or more types and tuples in Typescript
If you want to create a type for a array combining the types you already have, you can do so: type Modifiers = Array<ButtonTypeModifiers | ButtonMarginModifiers | ButtonSizeModifiers>; Or,…
-
6
votes1
answer209
viewsQ: Why, when an iterator is not used, is an emoji "broken" into two parts?
Considering the code passage below: const str = 'Olá! '; str.split('').forEach((char) => console.log(char)); Note that all characters were separated from the string correctly. However, the emoji…
-
4
votes3
answers97
viewsA: Does Hoisting occur with the variable within the function or any other block command?
In the first example, you are using var, which is an old way of declaring variables in Javascript. It can be said that there are Hoisting in var, since the declaration will be elevated to the most…
javascriptanswered Luiz Felipe 32,886 -
1
votes1
answer98
viewsA: Using`await` out of asynchronous function causes syntax error
First of all, it is worth saying that its function is incorrect. The result of request will never be returned by getJSON, since the return is inside the callback of function request, and not of the…
-
3
votes1
answer338
viewsA: How to capture all elements with the same class at once?
To select all elements with the class .btn, you must use the method querySelectorAll, that returns a NodeList. But since this method returns a list and not the element itself, you cannot expect the…