Most voted "react-hooks" questions
Hooks is a new feature included in React 16.8 that allows developers to use state and other React features in a functional component. Use this tag for Hooks related questions (useState, useCallback, useMemo, useEffect etc.).
Learn more…143 questions
Sort by count of
-
0
votes1
answer203
viewsHow to redirect to an external url using React useEffect?
I am trying to redirect to an external url ,using the vaiparala function by passing a parameter that I pick up from the click, the path arrives at the function correctly but the redirect does not is…
-
0
votes1
answer43
viewsHow to add new object at specific position of useState Hooks array
I have the following state in hook on Reactjs: const[faixas, setFaixas] = useState([ {albumId: 1, nome: "nome da musica"}, {albumId: 1, nome: "nome da musica"}, {albumId: 2, nome: "nome da musica"}…
-
0
votes2
answers56
viewsHow to pass a specific object as props in a generation of components?
Hello, I’m initiating the studies in React and when trying to create a code that generates components (in this case the "Box")where at the click of a button passing objects coming from a state to a…
-
0
votes1
answer206
viewsReact Hook useEffect has a Missing dependency: 'storeInfo'
I’m trying to use useEffect for a simple function, but error. It is not updating the page and saving the request I make with the function loadAll in the useState. When I load the page the result of…
-
0
votes1
answer2038
viewsError: Too Many re-renders. React Limits the number of renders to Prevent an Infinite loop
Eai, I started with reactjs a short time ago and decided to make a site with simple functions to learn, one of these functions would be to list in card format some data I receive from the backend,…
-
0
votes0
answers29
viewsIn which situations should I use useRef?
I recently read an article entitled You’re overusing useMemo: Rethinking Hooks memoization. In it, I saw something interesting that I hadn’t thought of before, using the useRef to store object…
-
0
votes1
answer40
viewsProblems consuming api - React
I am consuming an api that returns an array of products with Axios, but it returns a Promise, and I cannot use it in my component, because at the time the component renders, the Promise is still not…
-
0
votes0
answers35
viewsHow do I iterate through Textinput in React Native useRef with typescript
I have a Textinput that will be divided into 4 password entries. What I need is: 1 - Adding a number automatically switches to the next focus entry; 2 - when I delete the entry, I go back to the…
-
0
votes1
answer50
viewsFirestore React error on
I’m trying to get the information from my collection in firebase but am getting the following error: Typeerror: Undefined is not an Object (evaluating '_firebaseConnection.default.db.Collection')…
-
0
votes0
answers37
viewsHow to add items to a list of products coming from an React api
I have a system that I need to search for a product in an api by name, every time I click add I need to pick up the return of the api and include this product a list calculating the total value and…
-
0
votes1
answer25
viewsOpen isolated dropdown with useState and useRef
I have a sidebar where I’m using a dropdown while hovering over each icon on that sidebar. I am using useState to open the dropdown and would like to use only one state for everyone, but open each…
-
0
votes1
answer24
viewsRequest Loop in useEffect
I’m doing a post on my API and want to update my book list whenever I create a new book. My Post is working, but when I add my "list" inside the [list] in use useEffects a Loop is started and the…
-
0
votes1
answer24
viewsReact - When I try to use data from the API using useEffect and useState, the application does not read the data in the component’s Return
I am consuming the Deezer API, using useEffect and useState in Reactjs to list a particular track (an example), but when using the .map, to render, the following error is returned: TypeError:…
-
-1
votes2
answers553
viewsReact Hooks state does not update
I am facing a problem with upgrading a State using React Hooks. The problem is that subsequently the application of a .filter() I try to apply the resulting value of the filtering performed in a…
-
-1
votes2
answers168
viewsReact Native: Component does not find state data after setState
I’ve had this problem for weeks: I am using React Hooks to request an internal api using useEffect to make a request and then store the result within a setState. If I give a console.log the first…
-
-1
votes1
answer71
viewsRemove All from a list
My function of removing All is only removing the first Element that has been added to all. const handleRemoveItem = useCallback(() => { setTodos(todos.slice(todos.indexOf(+1))); }, [todos]);…
-
-1
votes1
answer42
viewsI am trying to make a favorite button in the js Act, that by clicking the icon with the classname"far fa-Heart" it changes to classname"fas fa-Heart"
import Cama from 'cama.png' import React from 'react' import styles from './styles.module.scss' export default function Recommend() { const [favorit, setFavorit ] = useState(); return ( <div…
-
-1
votes1
answer397
viewsThis is Undefined in React Hooks
Hello, I’m creating a JS system using React Hooks, but I came across a problem when I use <Route exact path ="/produto/:idProduto" component={Quiz}/> we were able to capture the id with const…
-
-1
votes1
answer105
viewsHow to take all pages of an API and show all data at once on screen using React Hooks?
Hi, I’m studying React Hooks and as a base I’m using a Rick and Morty API to show the characters on the screen https://rickandmortyapi.com/api/character/ However, it only shows twenty characters per…
-
-1
votes1
answer336
viewsModify only one React Hooks component
Hello, I’m running a simple application on Reactjs. I created some check buttons, which when clicked changes color, but I press these buttons on a map and when I click to change the color of one,…
-
-1
votes1
answer39
viewsGoogle maps addListener using React
I need to add the dragend event to get the center of the map google.maps.event.addListener(map, 'dragend', function(evt) { console.log(map.getCenter()); }); however do not know how to make this…
-
-1
votes1
answer52
viewsProblems with React-router-dom Withrouter
If you turn on, I started making an app and I needed a header menu for the transition, this would be a menu that is rendered on every page. That is why it was created and is ultimalized outside the…
-
-1
votes1
answer286
viewsView data from React Native API
Hi Dev’s I’m new in RN, I’m trying to show the return of a json, but I can’t access by the handle on the screen, only in the console. export default Function Functional() { const [date, setData] =…
-
-1
votes1
answer35
viewsReact Native refactorando class for Function Component
New in RN and I’m trying to refactor from the Component class to Function Component to use Hooks, but at the time of setting the function item. map(), here "setSentences(item);", not reacting,…
-
-1
votes1
answer43
viewsHow to change some attributes of an object with Hooks
I want to update only some attributes of an object, these attributes are varied, one time I want to update some, another time. Follow the example: const [myObject, setMyObject] = useState({…
-
-1
votes1
answer54
viewsHow to put optional parameter in Reactjs
I need to send a request, but there is a parameter that is optional, and I must only send it on one condition. It’s like this: const [blocoSelect, setBlocoSelect] = useState("nenhum"); params: {…
-
-1
votes0
answers19
viewsHow to Update a Component with Hooks
I have a form that when saving a record should update the list of users. When it was in the same component the list would update normally. Now I need to refresh the page to get the updated list. I…
-
-1
votes0
answers23
viewsChange parameter in API call with Reactjs
I’m using Axios to consume an API and create a personal project. endpoint is this: https://www.freetogame.com/api/games I added a "Learn more" button where I would redirect to a "page" where there…
-
-1
votes1
answer17
viewsReceive the value of an input variable and compare to a preset to generate an Alert and redirect
Good morning, I’m new to React Native and I’m trying to compare the value of a variable I received through a Textinput with an already preset to generate an Alert and redirect me to another screen,…
-
-1
votes0
answers21
viewsMy useReducer does not work
I’m making a shopping cart with useReducer and I can’t change the inCard for true and the qty to add one more to each click. What am I doing wrong? import React, { useReducer } from 'react' import…
-
-1
votes0
answers21
viewsa React state works perfectly on my localhost but when I do the hosting doesn’t work
Gallery export function () { const [estadogaleria, setestadogaleria] = useState (false) const [indice_galeria, setindice_galeria] = useState (0) const [indicehome, setindicehome] = useState (0)…
-
-2
votes1
answer92
viewsEslint problem in Reactjs with useEffect, in this case how do I not need to put the // Eslint-disable-line
Well, folks, I have a function that allows for some variables within it. However, it should only be executed when a dependency specific to it is changed. in the case of index useEffect(() => {…
-
-2
votes2
answers335
viewsValidate fields in React
I have some input fields, both are set to states. I would like to make sure that you only allow clicking on the button if these fields are filled in. Obs:. I am Using Hooks const [ name, setName ] =…
-
-2
votes2
answers380
viewsThe set function of the state of the React is not actually receiving and passing on the values
I don’t know pq, but when I try to make a request for my backend, the state of "posts" does not receive the value of Answer.data. That is, the two "console.log" have different values, while…
-
-2
votes2
answers1463
viewscreate dynamic select with Reactjs + Hooks
Hello. I am trying to create a form with four selects (Animal, Size, State and City) the state and city selects that are being a problem. One makes a request to present the Brazilian states (is…
-
-2
votes2
answers92
viewsdisplay React-Native modal array
Hello, I am developing an app for the internship and the supervisor asked that in the search field, the user has the option to choose which field to search for. I thought of making a modal with the…
-
-2
votes1
answer136
viewsAdd values from a json api and display results // React JS
My json api: { "chamado": [ { "id": 1, "numeroChamado": 435689, "sistema": "xx", "requerenteChamado": "xxx.xxx", "tecnicoChamado": "xxx.xxx", "statusChamado": "Processando", "valorBoleto": 350,…
-
-2
votes2
answers24
viewsDifferent behavior using useState and useContext/useReducer
I have a case that should be very common for you. I make a query of a sales list in a Rest API and at that time I set the status isLoading to true, so that a Spinner component I have is visible and…
-
-2
votes0
answers14
viewsSpecified route configuration error using Fuse React Maximum update Depth exceeded:
I am using the Fuse template for React and need to configure private routes for each specific user profile, following the documentation I set my route file by placing the path parameter and the…
-
-2
votes0
answers6
viewsError setting up context.Provider in a next.js project
Following staff, I started a project using Next.js, and after inserting some codes, I needed to create a Provider (myContext) to create global states, but when configuring Provider, my application…
-
-2
votes0
answers19
viewsReact JS - Why are my components within a MAP function not updating with useState?
React JS - Why my components within a MAP function are not updating with useState? I’m in the following situation: I receive a contact ARRAY from my API and use the MAP function to return contacts…
-
-2
votes0
answers23
viewsAsync/await not working in React typescript (Hooks)
I’m running a route-fed authentication. But this not respecting the await of the post in the login api. Sometimes it works locally but most of the time it "skips" the post. import React, {useState}…
-
-4
votes1
answer61
viewsuseState in Reactjs?
I’m starting to React after studying Javascript and trying to do a very simple thing, which is to write a name I one input and appear on the page. import React from 'react'; function App() { return…