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
votes2
answers98
viewsSelect does not let you select the option
Hello, I have a list of option of a select and I can’t select an item from the list. import React, { useState, useEffect } from 'react'; import styled from 'styled-components'; export default…
-
0
votes0
answers211
viewsHooks with Infinite Loop
My Hooks is in infinite loop, charging all the time, what I intend to do is to search the api when start the screen and when there are changes of status of the tasks reload, but it keeps reloading…
-
0
votes1
answer60
viewsRender Html
I am consuming a json where I have a key with the value of an html tag: import React, { useState, useEffect} from "react"; export const CardHome = () => { const [recebeDados, setRecebeDados] =…
-
0
votes2
answers44
viewsGrab list of objects within the array
I’m having some difficulty to get the values that are of my function and pass them to a list, follow the code: const [listaPais, setListaPais] = useState<{ id: number; name: string }[]>( [] );…
-
0
votes1
answer970
viewsUsedispatch() inside a useEffect() -> *Missing dependency*
ALERT: React Hook useEffect has a Missing dependency: 'Dispatcher'. Either include it or remove the dependency array React-Hooks/exhaustive-deps import React, {useEffect} from 'react' import…
-
0
votes1
answer103
viewsHow to run a Javascript function after loading the DOM using React Hooks?
I need to create several li tags based on an array and then insert them into a div, however I need to wait for that div to be created before doing so. Since React doesn’t have Domcontentloaded what…
-
0
votes1
answer229
viewsState returning Undefined
I’m not much for asking, right, but it’s keeping me up at night... I have the following function to format dates const DataFormat = (props) => { const data = props.split('T'); const [year, month,…
-
0
votes1
answer347
viewsComponent in Reactjs re-rendering child components without need, how to get around this?
When a component Father consequently updates its Son(s) (s) also and(are) updated(s), without at least changing any value of its props and states, for example: function Filho({item}) {…
-
0
votes1
answer79
viewssetInterval() does not work
I am creating a question application, where it displays a timer, if the timer reaches 0, the question will be lost (ie if the user does not answer in time), but when displaying the number is…
-
0
votes2
answers94
viewsChange State of Component called more than once
I have this code that is a simple counter of Truco. I made a component to count and called him to both teams. When it reaches above 11 points the Zera component was straight. But how am I calling…
-
0
votes0
answers199
viewsCleaning function in useEffect is not working
Hello! I am trying to cancel my api call using Axios when the component is unmounted, and although it seems to be being canceled, I still get the error: Can’t perform a React state update on an…
-
0
votes1
answer168
viewsReactjs - setState does not work with the first value in onClick
Bom di! I’m using React in version 16.11.0 and every time I use setState using function, the first value I Seto, it always comes blank. Follow the example below: //Declaração do State const [senha,…
-
0
votes1
answer828
viewsHow to use Localstorage in a functional React component
How can I use Localstorage in this case the way I did works only with class component Error that appears is: Typeerror: repositories is not a Function export default function Main() { const…
-
0
votes1
answer97
viewsText does not appear using React Hooks with Redux
I’m trying to get a string saved in my store state and put it in a text component, but the text is not showing up. To call the string, I’m doing it this way: import {useSelector} from 'react-redux'…
-
0
votes2
answers1538
viewsUpdate useEffect from the navigation.goBack page?
I’m developing a App in ReactNative using Expo, but I can’t update the useEffect(() => {}, []) of the previous route from navigation.goBack(). Example: Here time the Index page. function Index(){…
react-native react-navigation react-router react-hooks expoasked 4 years, 8 months ago Jéfferson Maurício 73 -
0
votes1
answer203
viewsHow to use "shouldComponentUpdate" with Hooks?
I have a component <Filho> who does not receive props, but is rendered again whenever the <Pai> has some status update (useState). To solve this I figured I could do, in the component…
-
0
votes1
answer88
viewsExpo - Invalid hook call inside function components
I was learning Expo, and I needed to create a dynamic list of counters. On my screen I have a button + that adds other squares, and each of these squares has a counter inside them, from what I…
-
0
votes1
answer177
viewsHelp with API/useEffect - React
I need to make a call to the API with React and for that I’m using Axios. Doing a test with the code below, on the console I can see the result: const [bill, setBill] = useState([]); useEffect(()…
-
0
votes1
answer511
viewsManipulating buttons in React.js
I am creating a small task system for a collaborator in the company where I work, it should display the tasks that must be completed on the day, until then I was able to display the tasks my problem…
-
0
votes1
answer203
viewsProblem when trying to call a function inside onPress - React Native
Hello, When trying to call a function that has a hook call the following error appears: And here’s the excerpt from the code: currentLocation.js import React, {useState} from 'react' export function…
-
0
votes0
answers23
viewsReact Hook does not accept value returned from an Axios template
As you can see I created a state called cur and within the map of the mat array, I’m making a request and I want to add the answer inside the event. But when I give console.log down there the state…
-
0
votes1
answer65
viewsHow to add the answer to an Axios request in an Array?
I am trying to put the answer to an Axios request inside an array, but I am receiving as a response a strange structure, as I will show in the following image: I created an Array, added my own name…
-
0
votes1
answer63
viewsJust open the clicked modal?
I have a map of a array object. <S.Section> {data.slice(oldItems, showItems).map((it, index) => { return ( <> <S.Box key={index} onClick={openDetails}> <S.Image…
-
0
votes1
answer79
viewsusing useEffect, setState and Sort for Array
I am using React Hooks to sort an array list by the 'points' item after I update an object item. After much tinkering with the code I managed to sort the Array in the 'Sorted' variable using useMemo…
-
0
votes1
answer173
viewsuseEffect does not recognize new value
The useEffect hook fires when some variable in your array refreshes. However, when the value of the variable remains the same, the hook simply ignores. This hook gets a value and a push on the array…
-
0
votes2
answers467
viewsShare a Hook from one component to another
My question is the following, I have a component in React called Navbar.jsx and would like the title no Navbar changed as soon as another component was opened. For example, when you open the…
-
0
votes0
answers52
viewsHow to correctly fill rows and columns using React datasheet?
I’m using the react datasheet to export and import data by pasting into my application tables. I expect all columns and rows I copy to be pasted normally. However, only one row and two columns are…
-
0
votes1
answer197
viewsComponent is rendered again whenever some input state is changed
Good morning guys. I am developing an application where the user registration is according to the option that it selects " Physical or Legal ". According to the option that he chooses a form is…
-
0
votes1
answer797
viewsHow to get an answer that is in the request header
I’m making a site that contains a forum and I need to pick up the amount of topics and registered users and with this in my back-end I send these quantities by header. I’m using in my back-end Cors,…
-
0
votes0
answers68
viewsHeaders on GET request with SWR
Good morning guys. I would like to know how I can pass headers on a GET request with the SWR. My need lies where I need to show all the registered products of a company, where the ID of this is…
-
0
votes0
answers23
viewsForm field does not focus on not stating data or contain invalid information. React-Hooks-Forms w/ Imask
I have a form for entering data such as credit card, as can be seen below: React.useEffect(() => { register({ name: 'cardNumber' }, { required: true, validate: isValidCardNumber }) register({…
-
0
votes1
answer389
viewsHow to make a Dynamic Checkbox with React Hook?
Guys, how can I make this dynamic checkbox? Because this way it is there I have to create a useState for each checkbox, but when I go to pull these values from the bank will come diametrically, how…
-
0
votes0
answers259
viewsReact component rendering twice
Guys I’m having a problem where my components are rendered 2/3 times and I’m suspicious of an implementation, but I’m not sure if it’s her fault. The implementation is as follows, I have a…
-
0
votes1
answer450
viewsArray using useState React.Js Hooks
I’m having a problem with a project I’m using React.js, and axios for consumption of API const [id, setId] = useState(''); const [image, setImage] = useState(''); const [att, setAtt] = useState(0);…
-
0
votes0
answers27
viewsHow do I change a Component React to a React Hooks function?
I want to take this whole Component and turn it into a hook with functions export default class App extends Component { constructor(props) { super(props); this.state = { selectedStartDate: null,…
-
0
votes1
answer155
viewsChange a Component Class React to a hook useState React-Native
I want to transform this code of class in a code of useState hook, wanted the same functionality as this code class has become the Hook export default class App extends Component {…
-
0
votes0
answers14
viewsAudio Expo does not pause the music
The sound plays normally, but the pause doesn’t work. I tried several algorithms and nothing worked. I think it’s something with the Promisses, because I don’t know much about asynchrony. But when I…
-
0
votes0
answers30
viewsas shows the exits exalta on the console
I am making a website to calculate account in the restaurant ,which is calculated in different example ways, in the account goes the items : main course, dessert, service fee, drink and snacks.…
-
0
votes1
answer150
viewsButton to close modal does not work
Hello, I’m having a problem to make my modal button close, it opens through the header of the normal application. I am using Reactjs 16.8 + Typescript 4.0.3. // Header/index.tsx import ContactForm…
-
0
votes1
answer31
viewsConditional rederization of a component from a selected item
good afternoon, I am going through difficulties to perform a conditional rendering that aims to render an Iconbutton only when and selected a value from the predefined list. my const with the list…
-
0
votes0
answers191
viewsHooks: Usestate with dynamic array manipulation in React Native
Good morning/afternoon/evening, I need your help if possible... I own a hook const [itens, setItens] = React.useState([ { id: 1, nome: "Item 1" }, { id: 2, nome: "Item 2" } ]); In fact it is blank,…
-
0
votes2
answers97
viewsReact components that receive ownership of an object as content do not update, how to deal with it?
I basically have a state that is a complex object and several components that render only one property of it, as the application is kind of large I made this prototype to illustrate: //Component…
-
0
votes0
answers25
viewsErrors when rendering a Sectionlist with an object array
I’m trying to insert a SectionList, but is returning in the console, in order, the following errors: Uncaught TypeError: Cannot read property 'length' of undefined The above error occurred in the…
-
0
votes0
answers27
viewsI can’t get the props or the api data to mount the page
Guys I’m having trouble with React with nextjs using Hooks with props , I set up a Carousel that shows several cards that use a map api to mount the cards and passes to Carousel , only when I click…
javascript-events react-hooks react-router maps-javascript-apiasked 4 years ago Everton Costa Souza 19 -
0
votes2
answers258
viewsSort array within another array with Reactjs
Staff I set up a table with the data of an array where will have attack and defense points of each player associated to a team. You will have the total points of attack and defenses of each player…
-
0
votes0
answers16
viewsModal Material-ui as soon as the page loads
Good morning, everyone! I’m having trouble understanding the logic and dynamics to make the modal of the material-ui appear as soon as the page is loaded, at the moment I haven’t touched the code…
-
0
votes0
answers46
viewsHow can I simplify HTTP requests in React?
I am currently working on a project that has modules with multiple API requests. Similarly, cases of "ordered" requests are frequent, that is, they are carried out as long as a given condition is…
-
0
votes1
answer65
viewsChoosing how many DIV’s to mount at a time within a . map()
Good morning guys, I went through a recent situation where I had to resolve the basis of a gambiarra but I wonder if there is a way to do what I had in mind at the time but could not accomplish. The…
-
0
votes1
answer32
viewsPassing method with parameter
Is it possible for me to use a function of the parent component that updates the state of that same component in ANOTHER component? (this function has a parameter that would be the new value to be…
-
0
votes1
answer33
viewsFunction turning empty object when sent as props (React)
I’m having trouble sending a function from one component to another. The function: const plus = () => { setQuantity(quantity + 1); } Send as a prop in the "Cart" <Cart chosen={productDataObj}…