Tag: c

59 votes
14 answers
1.3K views
React JSX: selecting "selected" on selected <select> option

In a React component for a <select> menu, I need to set the selected attribute on the option that reflec

avatar
Gigi
0 1 0 9
asked 07 September, 2021
52 votes
16 answers
611 views
Correct modification of state arrays in React.js

I want to add an element to the end of a state array, is this the correct way to do it? this.state.arrayvar.pu

avatar
Dorian
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.3K views
How to update nested state properties in React

I'm trying to organize my state by using nested property like this: this.state = { someProperty: {

avatar
Thurman
0 1 0 9
asked 07 September, 2021
44 votes
16 answers
1.3K views
Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag

I am trying to set up my React.js app so that it only renders if a variable I have set is true. The way my

avatar
Yolando
0 1 0 9
asked 07 September, 2021
62 votes
16 answers
2.5K views
Error: &apos;node-sass&apos; version 5.0.0 is incompatible with ^4.0.0

I've created a blank React project, using the command: npx create-react-app on npm v7.0.7 and Node.js v15

avatar
Chelsea
0 1 0 9
asked 07 September, 2021
54 votes
9 answers
1.1K views
Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await

There is a lot of talk about the latest kid in redux town right now, redux-saga/redux-saga. It uses generator

avatar
Stacia
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
2.4K views
Hide keyboard in react-native

If I tap onto a textinput, I want to be able to tap somewhere else in order to dismiss the keyboard again (not

avatar
Vi
0 1 0 9
asked 07 September, 2021
60 votes
7 answers
2K views
ReactJS - Does render get called any time "setState" is called?

Does React re-render all components and sub components every time setState() is called? If so, why? I thought

avatar
Freida
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
2.2K views
React - How to get parameter value from query string?

How can I define a route in my routes.jsx file to capture the __firebase_request_key parameter value from a UR

avatar
Tuan
0 1 0 9
asked 07 September, 2021
52 votes
10 answers
1.7K views
What&apos;s the difference between "super()" and "super(props)" in React when using es6 classes?

When is it important to pass props to super(), and why? class MyComponent extends React.Component { constru

avatar
Majorie
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
675 views
Perform debounce in React.js

How do you perform debounce in React.js? I want to debounce the handleOnChange. I tried with debounce(this.h

avatar
Nereida
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
705 views
Detect click outside React component

I'm looking for a way to detect if a click event happened outside of a component, as described in this ar

avatar
Xavier
0 1 0 9
asked 07 September, 2021
57 votes
18 answers
2.3K views
A component is changing an uncontrolled input of type text to be controlled error in ReactJS

Warning: A component is changing an uncontrolled input of type text to be controlled. Input elements should

avatar
Venice
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
1.7K views
Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

I am getting this error: Uncaught Error: Invariant Violation: Element type is invalid: expected a strin

avatar
Xavier
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
3K views
What is the difference between state and props in React?

I was watching a Pluralsight course on React and the instructor stated that props should not be changed. I&apo

avatar
Fabian
0 1 0 9
asked 07 September, 2021
60 votes
8 answers
588 views
What is the difference between using constructor vs getInitialState in React / React Native?

I've seen both used interchangeably. What are the main use cases for both? Are there advantages /

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
600 views
Show or hide element in React

I am messing around with React.js for the first time and cannot find a way to show or hide something on a page

avatar
Forrest
0 1 0 9
asked 07 September, 2021
62 votes
20 answers
2.7K views
Call child method from parent

I have two components: Parent component Child component I was trying to call Child's method from Parent,

avatar
Forrest
0 1 0 9
asked 07 September, 2021
62 votes
13 answers
3K views
How to get first N number of elements from an array

I am working with Javascript(ES6) /FaceBook react and trying to get the first 3 elements of an array that vari

avatar
Trudy
0 1 0 9
asked 07 September, 2021
56 votes
10 answers
2.8K views
Difference between npx and npm?

I have just started learning React, and Facebook helps in simplifying the initial setup by providing the follo

avatar
Freida
0 1 0 9
asked 07 September, 2021