Tags down


How to setState from function parameter in React

By : Dani Lozano
Date : September 16 2020, 06:00 AM
Does that help In order to use this in a callback function, as told in the comments you have to bind it in the constructor or use an arrow function.
Also, since your name is a variable, you can't update your state like:
code :
this.setState({ name: value }
handleChange = (name, value) =>
  this.setState({ [name]: value }, () => this.financeCalcualte());

Share : facebook icon twitter icon

React is it possible to setState with an function parameter?

By : Kristoffer Olsson
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Hello i am trying to use a function to set my Modals state and i got alot of modals so what i am doing is trying as this , Add square bracket [] to your code:
code :
openModal(state) {
  this.setState({ [state]: true}, () => console.log(this.state.doneModal));

React setState prevState parameter and Array#map

By : Diji
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , .map creates a new array, but the object inside the array are still reference to the state's object.
One approach is to shallow copy the state's object to the new array:
code :
const persons = this.state.persons.map( pers => {
  // Do the shallow copy
  if (pers.id === id) {
    return {
      name: value

  // Return the reference, because we don't do any mutations
  return pers;

React SetState Twice in Same Function

By : Sam Rajan
Date : March 29 2020, 07:55 AM
help you fix your problem First,setState is an asynchronous function,so you can't decide when the first setState runs.So I recommend to force it run synchronous.
code :
this.setState({chess_board: new_board},()=> {console.log(this.state.chess_board)})
setTimeout(this.chess_engine_move(),3000);// delay 3s

How to pass query parameter to api using map method and concatenate every json response to setState in react?

By : user2116901
Date : March 29 2020, 07:55 AM
I wish this helpful for you If I understand your question correctly, then the only adjustment needed here is to update your setState() logic so that you append articles from your response to the articles array in your state:
code :
this.state.newsPaper.map(async (querypara) => {

    const requstone = await fetch(`https:someapisources=${querypara}&apiKey=${api_key}`);
    const dataone = await requstone.json();

    // Concatenate articles from response (dataone) to array in state
        articles: this.state.articles.concat(dataone.articles)

React setState for API doesn't update even thought it gets new parameter

By : user3692636
Date : March 29 2020, 07:55 AM
help you fix your problem I'm guessing it is your getRecipes function. React's setState is "asynchronous, but not in the javascript async/await sense. It is more like state updates during the current render cycle are queued up to be processed for the next render cycle.
code :
getRecipes = async e => {
    loading: true

  await recipesRequest(e).then(response => {
      recipes: response,
      loading: false
getRecipes = e => {
    loading: true

  recipesRequest(e).then(response => {
      recipes: response,
      loading: false
Related Posts Related Posts :
  • can i use graphql in react without using Apollo?
  • Difference between different ways to initiate a react-native project?
  • Static value as hook input
  • How to render different Image source through locating the file REACT
  • Comparison Assignments in React Practical Tutorial
  • Why do I need to set a value of a component when assigning a state from event handler?
  • previous state persisting even after calling setState() with new data
  • Download files from an API by a React Native app using EXPO, and get the link of each file
  • How to call a function onClick which is defined in React Hooks useEffect()?
  • AWS amplify deploy failure due to aws-exports
  • set the state through a function in reactjs
  • ReactJS: How to avoid the re-rendeing the whole page if only one part is changed?
  • NextJS + Contentful => getEntries request within getInitialProps breaks production build
  • Gatsby conditional rendering of a component
  • onChange not updating React
  • react-hook-form with react-redux-firebase not working
  • Access external API from Firebase Hosted React App Created Using CRA
  • Removing subtasks in React, with hooks
  • How to update state of an object in state with another object in state
  • How to render HTML and Code stored in database using Reactjs component - getting rendered unformatted
  • Call Socket IO instance from a component or API route on NextJS
  • How to use axios to get api items in redux?
  • State Management in Ember application
  • How do I trigger a forced update with react-i18next?
  • React-table[v7] rendering with Storybook
  • Syntax error: Identifier 'App' has already been declared (11:7) Not posted anywhere else in the file
  • React Js with Visual studio 2017 with Typescript
  • How to use jest.spyOn with functional react component
  • Using one webpack project inside another with react hooks causes an error
  • React: Uncaught TypeError: tokenIds.map is not a function
  • Material-ui autocomplete clear value
  • Too many re-renders. React limits the number of renders to prevent an infinite loop. Updating state of a functional comp
  • how to change an item in an array using the useState hook in react?
  • Dockerize react application index.html missing
  • React Redux clean way to update nested objects?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk