score:3
Accepted answer
There are some issues in your code
- setState may be asynchronous, meaning state wont get updated immediately after setState is call. It is mentioned clearly in React docs: https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
- You should never directly modify the state inside componentDidMount It is also mentioned here: https://reactjs.org/docs/state-and-lifecycle.html#do-not-modify-state-directly So I suggest modify the code as below
componentDidMount() {
this.getDeductionInfosList(data, function(response){
this.createAppState({
group: [{ field: "DeductionTypeTitle" }]}, response.Result, true)
});
}
createAppState(dataState, items collapseAll) {
const dataResult = process( items, dataState);
if (collapseAll) {
dataResult.data.forEach(dataItem => dataItem.expanded = false);
}
this.setState({
dataResult: dataResult,
dataState: dataState
});
}
score:0
You have to transform the function to async
and use await
to the response.
async function getDeductionInfosList(data){ await GetRestrictionListService.getDeductionInfos(data, this.successGetDeductionInfos);}
Source: stackoverflow.com
Related Query
- How to get data from Api first and then call the my function?
- how can i send an api call from the supreme function to another component called product to change a mock data called cart: true and display in cart
- Get object array from axios and using return value call another axios function and append the output to first result
- How to use a data from the 1st API call and use that in my 2nd API call?
- What is the best place to pull data from query string, then call API and render components?
- How place a function outside the return and then call it from onChange react?
- How to get object key from the api call dynamically and change the payload structure format?
- React.JS, how to edit the response of a first API call with data from a second API call?
- How to make a second api call with data received from the first api call in Apollo client with React?
- How to call a GET api with string parameter after I login and passing the email address so the data will come out? (REACT.js)
- How can I use the selectedValue from the dropdown to then call an API using it and render the JSON?
- How do i set the state from one API call and use the data for URL in next API call?
- How to fetch API data from Axios inside the getServerSideProps function in NextJS?
- How to put a dynamic data from firestore in the function where() and also use the snap.size to count the total query to be passed in a graph?
- React Context : Get Data from API and call API whenever some events happens in React Component
- How to make the Service Worker cache data from API and update the cache when needed
- How to retrieve data from the server using fetch get method and show it in a table
- How to get the returned data from a smart contract function using ethers.js?
- Conditionally check value from context and then navigate after login in the same function call in React
- How do I pass the text data from firestore inside the expandable row and get the document ID to be passed inside the setState?
- How to get data from an API only once when the page is loaded using axios.get method?
- making second api call after getting data from the first api
- How get data from the state and edit the element in the form?
- How to fetch data from API and then pass it to another component in react after it is fully loaded?
- How to fetch sequence api calls where second api call need particular data from first api call result using react hooks?
- When i try to call the api data from axios i get 404 error
- How can I filter json data from api call in react into different sections of the component
- How to get the value from interface and use it on another function
- How to get a single data element from the database with Redux and React?
- How to get data from API and turn it into array list for Google Charts
More Query from same tag
- How to avoid the memory leak warning in my react application, even though i am cleaning up my useEffect?
- React-router history.push does not actually redirect
- Declaring function inside function in React
- componentWillReceiveProps is not triggered on react-router Link
- Trying to map through returned data after a form submit. NextJS
- chartjs-plugin-zoom not working with my React project
- How can I simulate a click on Highchart
- React/TypeScript: Specifically type props.children to component
- How to Swap 2 different background colours for the Paper component between dark and light theme in material UI?
- Notification number over badge Tailwind
- Strange order of execution react
- React Body Css with Bootstrap 4.5.2
- React element is not defined
- In ReactJS what does the following notation mean?
- Webpack duplicates packages in bundle
- How to add rowClassName to a particular row in antd table on onClick of the row and not after onMouseLeave
- Async Action creator test cases using jest in react
- How to reflect updated data in react application after changing feature flag value in launch darkly
- When does React create SyntheticEvents?
- Cannot import SVG file into react
- How can I style react-datepicker?
- The question about React.memo and performance optimisation
- Spring Boot (inject script in reactjs)
- TypeError: stripHtml is not a function
- Unable to trigger an update with Redux
- React not responsing to passed parameter variable
- react - conditional rendering inside component return function
- how to test if button click fired then it update the state or not?
- How to Draw Polyline on mapmyindia using React?
- Programmatically Navigating React Router V6 From React.Componet