react-state

ReactJS HREF Causes State Loss

回眸只為那壹抹淺笑 提交于 2021-02-11 14:37:52
问题 I have a parent component called EnrollForm with a BrowserRouter that routes to different sub-components which are the pages of my overall EnrollForm. Each time a sub-component page is filled out and next btn is clicked, all form fields are saved to sub-component state obj, then that state is passed to the parent EnrollForm state. This flow is working correctly.. however when I added the line of code to href to the next sub-component, the parent EnrollForm state is deleted and so is BioForm's

ReactJS HREF Causes State Loss

梦想的初衷 提交于 2021-02-11 14:35:10
问题 I have a parent component called EnrollForm with a BrowserRouter that routes to different sub-components which are the pages of my overall EnrollForm. Each time a sub-component page is filled out and next btn is clicked, all form fields are saved to sub-component state obj, then that state is passed to the parent EnrollForm state. This flow is working correctly.. however when I added the line of code to href to the next sub-component, the parent EnrollForm state is deleted and so is BioForm's

Reversing an array stored in State doesnt force re-render of component in React

只谈情不闲聊 提交于 2021-02-10 17:45:54
问题 This is part of a larger component but I've summarised it in a reproducible example below: import React, {useState} from 'react' function App() { const [data,setData] = useState([{name:'first'},{name:'second'},{name:'three'}]) // Function to reverse a given array const reverseArray = (array) => { var reverseArray = array.reverse(); return reverseArray; } return ( <div> {data.map((item,index)=>{ return <h1 key={index}>{item.name} index: {index}</h1> })} {/*When I click this I expect the div

Fetch data with a custom React hook

拜拜、爱过 提交于 2021-02-09 07:29:11
问题 I'm newbie in React but I'm developing an app which loads some data from the server when user open the app. App.js render this AllEvents.js component: const AllEvents = function ({ id, go, fetchedUser }) { const [popout, setPopout] = useState(<ScreenSpinner className="preloader" size="large" />) const [events, setEvents] = useState([]) const [searchQuery, setSearchQuery] = useState('') const [pageNumber, setPageNumber] = useState(1) useEvents(setEvents, setPopout) // get events on the main

state undefined: while sending post request from react app

落花浮王杯 提交于 2021-01-29 04:54:47
问题 I am new in react and trying to send post request to an api and getting state undefined while sending post request from react app, i this occurs because state stores data as an object. Dont know how to solve this. i would really appreciate some help. compmonent.js import React, { Component } from 'react' class Register extends Component { register () { // alert('register') console.warn('state', this.state) fetch('http://localhost:8000/api/v1/accounts/registration/', { method: 'POST', headers:

state undefined: while sending post request from react app

爷,独闯天下 提交于 2021-01-29 04:53:40
问题 I am new in react and trying to send post request to an api and getting state undefined while sending post request from react app, i this occurs because state stores data as an object. Dont know how to solve this. i would really appreciate some help. compmonent.js import React, { Component } from 'react' class Register extends Component { register () { // alert('register') console.warn('state', this.state) fetch('http://localhost:8000/api/v1/accounts/registration/', { method: 'POST', headers:

React useState option value 1 step behind onChange selection

送分小仙女□ 提交于 2021-01-28 14:40:08
问题 The size.value state is one option behind when the _updateData function triggers onChange of the <select> . For example, Let's say the starting defaultValue option of <select> is "All", locations is empty...the option is changed to "Medium", locations is "All"...the option is changed to "Large", locations is "Medium"...and so on. Initially I want the _updateData function to run onload with "All" selected which is not working either, it throws the error Cannot read property 'target' of

React renders without actually changing the state when setInterval is used

大憨熊 提交于 2021-01-28 11:36:10
问题 I'm going to introduce my question in two steps with slightly different code blocks in both. Step 1: Below we have a React application which renders itself every two seconds and therefore causes the browser to print render to the console. If the user presses any key, the renders will stop which in turn stops the console prints. Please ignore the line commented out for now. import { useState, useEffect, useRef } from 'react'; function App() { const [number, setUpdate] = useState(0); const

How to pass async state to child component props?

被刻印的时光 ゝ 提交于 2021-01-22 18:30:31
问题 I'm new to react and I am trying to fetch data from an API and pass the data to a child component. I've passed the data to the state on my parent component, however, when I pass it to the child component as props it logs as an empty array. I'm sure there is something simple I am overlooking but I don't know what, my code is below PARENT COMPONENT import React, {Component} from 'react'; import Child from '../src/child'; import './App.css'; class App extends Component { constructor(props) {

How to pass async state to child component props?

♀尐吖头ヾ 提交于 2021-01-22 18:26:42
问题 I'm new to react and I am trying to fetch data from an API and pass the data to a child component. I've passed the data to the state on my parent component, however, when I pass it to the child component as props it logs as an empty array. I'm sure there is something simple I am overlooking but I don't know what, my code is below PARENT COMPONENT import React, {Component} from 'react'; import Child from '../src/child'; import './App.css'; class App extends Component { constructor(props) {