logo
down
shadow

React doesn't update component after state changes


React doesn't update component after state changes

By : lalitha
Date : October 22 2020, 08:10 AM
To fix this issue There are a few issues, one or more of which are probably the problem (particularly #4):
code :
this.setState(this.setState(res.data));
this.setState(res.data);


Share : facebook icon twitter icon
Checkbox doesnt update on react on child even if the parent state update?

Checkbox doesnt update on react on child even if the parent state update?


By : M-A Savard
Date : March 29 2020, 07:55 AM
With these it helps This is the code from the parent: , This code can also be written this way:-
code :
_handleSelectedTodo(e) {
  e.preventDefault(); 
  this.setState({checkedIds: [...this.state.checkedIds, e.target.value]});
}
render () { ...
<ul>
{todos.map((todo,todoIndex) => {
  let isChecked = (this.state.checkedIds.indexOf(todo.id) >= 0);
  return (
     <Todo
       key={todo.id}
       {...todo} // pass all the todo property
       onClick={(id) => onTodoClick(todo.id)} //This event should be binded to 'this' inside the constructor
       onTrashClick={(todoIndex) => onDeleteClick(todoIndex)}
       handleSelectedTodo = {this._handleSelectedTodo}
       checked={isChecked}
     />
  )
 });
}
<input
  checked={this.props.checked}
  onChange={handleSelectedTodo}
  type="checkbox"
  value={id}
></input>
React setState doesnt update state while changing an image

React setState doesnt update state while changing an image


By : greg_orke
Date : March 29 2020, 07:55 AM
Hope this helps You are passing the context of handleClick as null , that should be this , means ref to current component.
Change this :
code :
this.handleClick.bind(null,`'assets/images/products/17.jpg'`)
this.handleClick.bind(this,'assets/images/products/17.jpg')
Simple React Component State, setState(...): Can only update a mounted or mounting component

Simple React Component State, setState(...): Can only update a mounted or mounting component


By : M. Wang
Date : March 29 2020, 07:55 AM
it fixes the issue Omar's solution is correct, but certain linters might get mad at you for creating an anonymous function in a render function (for performance reasons). You also have 2 other options that are more performant.
code :
forgetValue = () => {
}
constructor() {
  this.forgetValue = this.forgetValue.bind(this)
}
React Child component don't update when parent component's state update

React Child component don't update when parent component's state update


By : markus
Date : March 29 2020, 07:55 AM
will help you componentDidMount is only called once during initial mounting, so your this.state.rows does not get updated afterwards.
Add in componentDidUpdate to make sure new data is fetched whenever props have changed:
code :
componentDidMount() {
  this.setData();
}

componentDidUpdate(prevProps) {
  if (this.props !== prevProps) { // only fetch if props changed
    this.setData();
  }
}

setData() {
  const { records, API, placeURI } = this.props;
  const results = records.results.map((p_id) => {
    const dataURI = `${placeURI}${p_id.place_id}${API}`;
    const proxyUrl = 'https://cors-anywhere.herokuapp.com/';
    return fetch(proxyUrl + dataURI)
      .then(res => res.json())
      .then((data) => {
        const jsonData = JSON.parse(JSON.stringify(data));
        // console.log(dataURI);
        return jsonData.result;
      });
  });
  // I wait for all fetch results before updating the state
  // If you prefer to update the state for each row, you can use your original code  
  Promise.all(results)
    .then(res =>
      this.setState(prevState => ({
        rows: [...prevState.rows, ...res],
      })))
    .catch(e => console.log(`Error! ${e.message}`));
}
How can I update a component's state based on its current state with React Hooks?

How can I update a component's state based on its current state with React Hooks?


By : user2963493
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can pass an updater function just like with setState. So, in this code, you'd run:
code :
setProgress(progress => ({ ...progress, [videoUrl]: "downloading" }));
Related Posts Related Posts :
  • Chrome-Extension/JavaScript How to make all links on page have no effect?
  • Websocket issue Internet Explorer
  • sessionStorage value becomes null in other tab in AngularJS
  • Split URL from position x to the end in Javascript
  • How to set value of input field with NgIf in Angular 4
  • invalidStateError for second time screenshare on Chrome
  • How do you pass a value to the variable in a xhr.setRequestHeader?
  • I cant start nodemon on my windows 10
  • Nested if else jumps out from the main if else in javascript
  • Iterate through all collections and remove them
  • ES6 - Value of a variable in template string does not increment
  • how to get content of html table cell using javascript javascript depending on checkbox
  • Node.js Working with Multiple Tier SQL
  • Can't allow Cross-Origin Request in local Nodejs server
  • Datatables orderable=false directly on table
  • Dynamically load js content with iron router in meteor using array in return statement
  • Limit checkbox to 2, but moving the select instead of blocking it
  • Why itsn't displaying marker on map?
  • jQuery target next of the same class in the whole DOM
  • encoding must be a valid encoding error in process encoding
  • How to do a date range to view data from selected date highcharts
  • How do I refactor this composed function with Ramda.js?
  • jQuery to serialize selected option's value, not label
  • Convert object to Chartis.js structure
  • Dynamic import with not bundled file
  • Click handler not firing for elements rendered in Ajax Callback - only in Safari
  • Math.max.apply gives an error CreateListFromArrayLike called on non-object
  • get the parent nodes to a given node in d3 dendogram
  • is-dropdown-submenu-parent makes links unclickable on Opera and Chrome
  • JS: Sum column values and updating result on change
  • Query against nested object keys
  • Fullcalendar getting its parent colspan
  • How to retrieve a dynamic number of elements by id
  • How to access redux variables and functions from deep components
  • Efficiently access Array.prorotype.filter single-item returns
  • PHP var into Javascript
  • How to parse json with javascript/jquery if content matches string
  • How can I make a pyramid based on alphabet?
  • Javascript sorting a csv rows and displaying in table
  • How to get specific data from json from api using ajax. The json looks strange to me
  • react js html5 video not working
  • Javascript Angular 4 Change ngClass from another Component
  • Hide multiple table columns with javascript
  • Convert datetime to ISO Format using moment js
  • Dynamically adjust canvas size depending on content
  • setTimeout function with document on click
  • Need advice on nested Promises.all
  • Google Captcha expiration time
  • Syntax of Javascript TAPE unit test
  • Parse php json to javascript
  • Write to Internet Explorer javascript console with vba in excel
  • 2 Forms with Jquery
  • Why the loop stops right in the middle?
  • filter system for restaurant booking
  • how to add active class in framework nav menu when (add/edit) pages are opened
  • Port a js map in dart
  • How to get value from select using javascript
  • Audio won't be muted with JavaScript - removing audio tags with mutationobserver needed
  • How to include an HTML/Javascript game into reactJS website
  • Convert Nodejs server into node module
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org