Skip to content

How to update the value dynamically after api call #17

Answered by srivastavaanurag79
Centeos asked this question in Q&A
Discussion options

You must be logged in to vote

I think this would update your list:

use

setReporting({...reporting, list: rd});

instead of

setReporting({
 list:rd,
 value: value.text,
 selectedList: value.selectedList,
 error: '',
});

please refer to this guide: useState in React: A complete guide for a better understanding of React's useState hook.

your code should look like this:

const [reporting, setReporting] = useState({
    value: '',
    list: [],
    selectedList: [],
    error: '',
  });

  const FetchReportingEmployee = () => {
    console.log("start reporting");
    let params = {
      AddedByUserID: userID,
    };
    Provider.getAll(`master/getreportingemployeelist?${new URLSearchParams(params)}`)
      .then((response…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by srivastavaanurag79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #16 on September 16, 2022 10:58.