Skip to main content
Filter by
Sorted by
Tagged with
907 votes
21 answers
925k views

I am trying to learn hooks and the useState method has made me confused. I am assigning an initial value to a state in the form of an array. The set method in useState is not working for me, both with ...
Pranjal's user avatar
  • 9,183
27 votes
7 answers
38k views

How to create a protected route with react-router-dom and storing the response in localStorage, so that when a user tries to open next time they can view their details again. After login, they should ...
learner62's user avatar
  • 630
172 votes
6 answers
121k views

I have a counter and a console.log() in an useEffect to log every change in my state, but the useEffect is getting called two times on mount. I am using React 18. Here is a CodeSandbox of my project ...
hossein fti's user avatar
  • 1,820
432 votes
10 answers
266k views

I'm reading Forms section of reactjs documentation and just tried this code to demonstrate onChange usage (JSBIN). var React= require('react'); var ControlledForm= React.createClass({ ...
Salah Eddine Taouririt's user avatar
1095 votes
32 answers
1.4m views

I'm building a React component that accepts a JSON data source and creates a sortable table. Each of the dynamic data rows has a unique key assigned to it but I'm still getting an error of: Each ...
Brett DeWoody's user avatar
1306 votes
63 answers
916k views

I'm using React-router and it works fine while I'm clicking on link buttons, but when I refresh my webpage it does not load what I want. For instance, I am in localhost/joblist and everything is fine ...
DavidDev's user avatar
  • 13.4k
2375 votes
51 answers
1.8m views

With React Router, I can use the Link element to create links which are natively handled by React Router. I see internally it calls this.context.transitionTo(...). I want to do navigation. Not from a ...
George Mauer's user avatar
14 votes
5 answers
22k views

Please I need help on react-router-dom, I am new to the library and can seem to find any solution since. I am getting three results from an api call, in which I map over the data to render it on UI, ...
Shadow_net's user avatar
147 votes
7 answers
87k views

I understand that React tutorials and documentation warn in no uncertain terms that state should not be directly mutated and that everything should go through setState. I would like to understand why, ...
Marcus Junius Brutus's user avatar
176 votes
15 answers
217k views

I would like to ask why my state is not changing when I do an onClick event. I've search a while ago that I need to bind the onClick function in constructor but still the state is not updating. Here's ...
Sydney Loteria's user avatar
218 votes
11 answers
492k views

So I have this: let total = newDealersDeckTotal.reduce(function(a, b) { return a + b; }, 0); console.log(total, 'tittal'); //outputs correct total setTimeout(() => { this.setState({ ...
The worm's user avatar
  • 5,908
642 votes
36 answers
503k views

I'm trying to organize my state by using nested property like this: this.state = { someProperty: { flag:true } } But updating state like this, this.setState({ someProperty.flag: false });...
Alex Yong's user avatar
  • 7,675
626 votes
19 answers
942k views

I want to add an element to the end of a state array, is this the correct way to do it? this.state.arrayvar.push(newelement); this.setState({ arrayvar:this.state.arrayvar }); I'm concerned that ...
fadedbee's user avatar
  • 45.2k
193 votes
9 answers
199k views

I have just found that in react this.setState() function in any component is asynchronous or is called after the completion of the function that it was called in. Now I searched and found this blog (...
Anup's user avatar
  • 2,454
886 votes
24 answers
1.2m views

With React 16.8.6 (it was good on previous version 16.8.3), I get this error when I attempt to prevent an infinite loop on a fetch request: ./src/components/BusinessesList.js Line 51: React Hook ...
russ's user avatar
  • 8,903
2099 votes
88 answers
2.2m views

I'm trying to do something like the following in React JSX (where ObjectRow is a separate component): <tbody> for (var i=0; i < numrows; i++) { <ObjectRow/> } </...
B Robster's user avatar
  • 42.2k
547 votes
13 answers
1.3m views

I can hit this endpoint, http://catfacts-api.appspot.com/api/facts?number=99 via Postman and it returns JSON Additionally I am using create-react-app and would like to avoid setting up any server ...
dwww's user avatar
  • 5,728
16 votes
3 answers
11k views

I am building a Netflix clone application, and I am using react-router-dom v5 to switch between different pages. However, when I click the Link tag in Navbar.jsx, the URL changes, but the ...
A_M's user avatar
  • 338
244 votes
19 answers
90k views

I am writing a simple component in ES6 (with BabelJS), and functions this.setState is not working. Typical errors include something like Cannot read property 'setState' of undefined or this....
user3696212's user avatar
  • 3,440
748 votes
7 answers
188k views

I have been reading a bunch of React code and I see stuff like this that I don't understand: handleChange = field => e => { e.preventDefault(); /// Do something here }
jhamm's user avatar
  • 25.1k
976 votes
24 answers
891k views

I have two components: Parent component Child component I was trying to call Child's method from Parent, I tried this way but couldn't get a result: class Parent extends Component { render() { ...
N8FURY's user avatar
  • 10.1k
443 votes
21 answers
762k views

I'm trying to send data from a child component to its parent as follow: const ParentComponent = React.createClass({ getInitialState() { return { language: '', }; }, ...
Birish's user avatar
  • 5,842
283 votes
7 answers
210k views

My React Component is rendering twice. So, I decided to do a line-by-line debug, and the problem is here: if ( workInProgress.mode & StrictMode) { instance.render(); } React-dom....
Marry Joanna's user avatar
  • 2,833
25 votes
4 answers
67k views

10:04:32 PM [vite] Internal server error: [postcss] It looks like you're trying to use tailwindcss directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue ...
amos murmu's user avatar
23 votes
2 answers
22k views

I am having trouble writing code to render a login page with no navbar and sidebar. I have come across some pages that ask similar questions but none seem to pertain to my current situation. How to ...
RockoDaBoat's user avatar
1465 votes
33 answers
1.0m views

I'm trying to find the proper way to define some components which could be used in a generic way: <Parent> <Child value="1"> <Child value="2"> </Parent> There is a logic ...
plus-'s user avatar
  • 46.7k
2567 votes
72 answers
3.5m views

I created the default IntelliJ IDEA React project and got this: Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/hash:67:19) at Object.createHash (...
a1cd's user avatar
  • 25.8k
593 votes
20 answers
916k views

I was trying the useEffect example something like below: useEffect(async () => { try { const response = await fetch(`https://www.reddit.com/r/${subreddit}.json`); const json = ...
RedPandaz's user avatar
  • 6,376
47 votes
3 answers
14k views

Ok, i'll try and make this quick because it SHOULD be an easy fix... I've read a bunch of similar questions, and the answer seems to be quite obvious. Nothing I would ever have to look up in the ...
Dan's user avatar
  • 799
559 votes
26 answers
1.0m views

I have a relatively straightforward issue of trying to add inline scripting to a React component. What I have so far: 'use strict'; import '../../styles/pages/people.scss'; import React, { Component ...
ArrayKnight's user avatar
  • 7,426
308 votes
7 answers
556k views

When a react component state changes, the render method is called. Hence for any state change, an action can be performed in the render methods body. Is there a particular use case for the setState ...
Sahil Jain's user avatar
  • 3,819
184 votes
6 answers
97k views

I am playing around with the ReactJS framework on JSBin. I have noticed that if my component name starts with a lowercase letter it does not work. For instance the following does not render: var ...
shaunakde's user avatar
  • 3,118
1499 votes
21 answers
661k views

What does the ... do in this React (using JSX) code and what is it called? <Modal {...this.props} title='Modal heading' animation={false}>
Thomas Johansen's user avatar
471 votes
22 answers
1.2m views

axios POST request is hitting the url on the controller but setting null values to my POJO class, when I go through developer tools in chrome, the payload contains data. What am I doing wrong? Axios ...
Srikanth Gowda's user avatar
330 votes
30 answers
659k views

In my Next.js app I can't seem to access window: Unhandled Rejection (ReferenceError): window is not defined componentWillMount() { console.log('window.innerHeight', window.innerHeight); }
Leon Gaban's user avatar
  • 39.4k
55 votes
9 answers
31k views

I am developing an application in which I check if the user is not loggedIn. I have to display the login form, else dispatch an action that would change the route and load other component. Here is my ...
Gaurav Mehta's user avatar
0 votes
1 answer
3k views

I followed all the steps mentioned in the Tailwind v4 docs, to setup TailwindCSS v4 with parcel . After setup when i am running local server then i got this error. Server running at http://localhost:...
Vatshal Negi's user avatar
700 votes
49 answers
527k views

How do you perform debounce in React? I want to debounce the handleOnChange function. I tried with debounce(this.handleOnChange, 200), but it doesn't work. function debounce(fn, delay) { var timer = ...
Chetan Ankola's user avatar
807 votes
26 answers
592k views

I am writing code so that before the data is loaded from DB, it will show loading message, and then after it is loaded, render components with the loaded data. To do this, I am using both useState ...
J.Ko's user avatar
  • 9,041
495 votes
24 answers
1.0m views

In the current version of React Router (v3) I can accept a server response and use browserHistory.push to go to the appropriate response page. However, this isn't available in v4, and I'm not sure ...
Chris's user avatar
  • 6,204
435 votes
33 answers
773k views

Problem I am writing an application in React and was unable to avoid a super common pitfall, which is calling setState(...) after componentWillUnmount(...). I looked very carefully at my code and ...
Igor Soloydenko's user avatar
285 votes
16 answers
163k views

I'm trying out the new React Hooks and have a Clock component with a time value which is supposed to increase every second. However, the value does not increase beyond one. function Clock() { ...
Yangshun Tay's user avatar
  • 53.7k
366 votes
40 answers
1.8m views

In a React app component which handles Facebook-like content feeds, I am running into an error: Feed.js:94 undefined "parsererror" "SyntaxError: Unexpected token < in JSON at position 0 I ran ...
Cameron Sima's user avatar
  • 5,415
224 votes
12 answers
177k views

class PlayerControls extends React.Component { constructor(props) { super(props) this.state = { loopActive: false, shuffleActive: false, } } render() { var ...
Maximus S's user avatar
  • 11.2k
600 votes
26 answers
665k views

My structure looks as follows: Component 1 - |- Component 2 - - |- Component 4 - - - |- Component 5 Component 3 Component 3 should display some data depending on state of Component 5. Since ...
Wojciech Kulma's user avatar
200 votes
14 answers
227k views

I don't know why my React component is rendering twice. So I am pulling a phone number from params and saving it to state so I can search through Firestore. Everything seems to be working fine except ...
Raul Sanchez's user avatar
  • 2,069
123 votes
9 answers
49k views

I'm new to both ES6 and React and I keep seeing arrow functions. Why is it that some arrow functions use curly braces after the fat arrow and some use parentheses? For example: const foo = (params) =&...
dkimot's user avatar
  • 2,299
937 votes
57 answers
1.0m views

I'm looking for a way to detect if a click event happened outside of a component, as described in this article. jQuery closest() is used to see if the target from a click event has the dom element as ...
Thijs Koerselman's user avatar
357 votes
8 answers
958k views

How do I select certain bars in react.js? This is my code: var Progressbar = React.createClass({ getInitialState: function () { return { completed: this.props.completed }; }, ...
user504909's user avatar
  • 9,609
114 votes
4 answers
216k views

If you have an array as part of your state, and that array contains objects, whats an easy way to update the state with a change to one of those objects? Example, modified from the tutorial on react: ...
waterlooalex's user avatar

1
2 3 4 5
531