Posts by Rodrigo Amaral • 714 points
29 posts
-
0
votes3
answers67
viewsA: Take the url and change the value?
Create a utility function that uses Web Apis URL and Urlsearchparam. These Apis work in all browsers except possibly Internet Explorer (for a change). The example below can be used anywhere and has…
-
2
votes1
answer227
viewsA: localstorage with React Redux
createStore does not admit 4 arguments, but only 3. Reducer (Function) preloadedState (any) Engineering () I played an example here, changing just about that: loading the state from the localStorage…
-
1
votes1
answer22
viewsA: Is it possible to set the number of items displayed in a material table per device?
Use the following function inside the component. First, make sure it works the way you expect, testing in Firefox/Chrome/etc in devtools responsive mode (Ctrl + shift + M). In my case, the printa…
-
1
votes1
answer23
viewsA: How to insert multiple phones in a tag next to, from a enter or tab, or even a button? React
You need two states: the textual input and an array of phones. As these states are related, it is better to use the hook useReducer that use two useState. We have 3 possible actions: type something,…
reactanswered Rodrigo Amaral 714 -
1
votes1
answer272
viewsA: how to make React render a table
React components are not HTML strings, as you would in a jQuery of life. You must use map whenever making a list of components of arbitrary size. function Principal() { const altura = 5; const…
-
0
votes1
answer256
viewsA: Styled-Component does not activate style
You first need to install an extension to highlight the CSS syntax of Styled-Components, after all it is just a string inside your Typescript file. Install…
-
-2
votes1
answer55
viewsA: Video does not appear when I build the project
Static media files should be imported as if they were Javascript files. For example, the following works in the production build: // nos imports: import videoFile from '../assets/video.mp4' // no…
-
0
votes1
answer21
viewsA: Create javascript object with other objects
You can turn one structure into another: const original = [ { nome: 'Fulano', setor: 'Produção', filial: 1 }, { nome: 'Ciclano', setor: 'Administrativo', filial: 2 }, { nome: 'Maria', setor:…
-
1
votes1
answer55
viewsA: What is the coplexity of my solution?
The algorithm loop gives the answer. At worst, the output condition set.has(currValue) will never be true. This causes each element of the array to be visited at least once. And it could not be…
-
2
votes1
answer57
viewsA: Error in useEffect accessing API data
I downloaded your project and tried to debug that problem. As I do not have access to the bank, the app does not starta and my diagnosis may not be 100% correct, but here we have the following…
-
7
votes1
answer3465
viewsA: Working with environment variables in Reactjs
Create React App accepts the following files by default, without having to install the env-cmd: .env: pattern. .env.local: Local overlays. This file is uploaded to all environments except test.…
-
5
votes2
answers165
viewsA: Function with two parentheses? function()()
It might be easier to understand Allan Juan’s answer if you assign the return of the high-order function to a variable. function soma(umNumero) { return (outroNumero) => umNumero + outroNumero; }…
-
0
votes3
answers392
viewsA: How to use reduce in an object array in React
Use map over an array to create a list of components for each item. Use filter to filter an array according to a certain criterion. For example, to list only the red fruits. Use reduce to transform…
-
2
votes2
answers170
viewsA: I want to generate 4 random values from an array. How can I do it?
The accepted answer works, but it has two small problems. The first, and largest, is that it produces k-permutations with non-uniform probabilities. By testing this function several times, it is…
-
1
votes1
answer729
viewsA: How to call a Function from another file, within a Function from the main file?
Fix a demo on Codesandbox which certainly does not match the functionality you want, but exemplifies how to import files and extract Hooks. For code reuse, use import. You typically import…
reactanswered Rodrigo Amaral 714 -
0
votes3
answers37
viewsA: Doubt in the execution
As already answered, onClick is a prop that should receive a function. You didn’t pass a function, you passed the return of a function. The difference is very clear in the example below, which I put…
-
0
votes1
answer31
viewsA: Problems when rendering React component after filter array
The filter method will always filter the array whose method is applied. This never increases its size to the original value, filter at best will return a copy of transactions previous. That is, you…
reactanswered Rodrigo Amaral 714 -
1
votes1
answer23
viewsA: Live search using React-Redux
The code provided is incomplete, but you can see what is happening. const works = state.brandList.filter(item => item.name === value); This line filters the brandList array with items whose name…
-
2
votes1
answer199
viewsA: Return key and value pair using a map
The object date is very bad for this type of task. If you have the option to edit it for an array of pairs { option, value}, everything will be better. If you don’t have this option, for example, if…
-
1
votes1
answer4512
viewsA: Get value from an input type='text' React
Its component makes two (separate) actions: 1) updates the input text; 2) sends this text to Alert. Therefore, you should remove this.handleChange() from the handleSubmit method. Working example:…
-
1
votes1
answer480
viewsA: React using Redux, not saving application status
I implemented your code in the Codesandbox, ignoring some missing parts. Almost always, when using React-Redux, an action fired apparently has no effect on the store, it is because the dispatch is…
-
0
votes1
answer75
viewsA: Using useState in React but not as I imagine
The example does not show what the Pivot component would be, but it is likely that the use of refs is unnecessary in this case (as it is in 99% of cases). Just like you can pass the state…
reactanswered Rodrigo Amaral 714 -
0
votes1
answer29
viewsA: How to set a state that is in a constant with React with a function
The function setAulas should be the only way to update the aulas. For example, with setAulas(novoObjetoAulas). Here is a complete example, with demonstration in Codepen: function Component() { const…
-
3
votes2
answers223
viewsA: Merge an Object with an ES6 Javascript Object Array!
It is preferable to use reduce, as in the accepted answer. But if you prefer a more imperative method: let content = { cd_empresa: 200, cd_produto: 13287, cd_status: 604, dt_validade:…
-
0
votes2
answers125
viewsA: How to know if a certain value is within a specific table
If the object in question is an array and contains only primitive values, then the recommended function is: local function pertence(nome, array) for _, valor in ipairs(array) do if nome == valor…
luaanswered Rodrigo Amaral 714 -
1
votes1
answer154
viewsA: Web application with React making infinite requests
Transform that line <FormUsuario Listar={this.Listar()} /> in <FormUsuario Listar={this.Listar} /> Executing the function inside the render causes a new request, which causes a setState,…
-
2
votes7
answers620
viewsA: How to access a circular array?
Using closures, it is possible to generate a function foo which, whenever invoked, returns the next element of the array, although it is modified during the code. function getElement(list) { if…
-
0
votes2
answers55
viewsA: How do I set the state with local dynamic json?
If JSON will be outside the folder src, for example in public, you should get it through an Xmlhttprequest request, possibly using the function fetch. import React from "react"; import ReactDOM from…
-
2
votes2
answers2451
viewsA: React, why use props in the constructor?
Why use super? The keyword super is used to access the parent object of an object, in other cases it is used to access the parent class of a class. When used in the constructor of a class, super…