setstate

React setState not updating state

人盡茶涼 提交于 2019-12-27 10:32:29
问题 So I have this: let total = newDealersDeckTotal.reduce(function(a, b) { return a + b; }, 0); console.log(total, 'tittal'); //outputs correct total setTimeout(() => { this.setState({dealersOverallTotal: total}); }, 10); console.log(this.state.dealersOverallTotal, 'dealersOverallTotal1'); //outputs incorrect total newDealersDeckTotal is just an array of numbers [1, 5, 9] e.g. however this.state.dealersOverallTotal does not give the correct total but total does? I even put in a timeout delay to

setState not changing value in gridview in flutter

蓝咒 提交于 2019-12-25 18:18:07
问题 basically i m updating list value that used in gridview, when i click on gridview card, i m changing color of that card. when i print color value it did changing but in gridview has no effect. Plz suggest me what to do? is my logic approach is wrong ? class FilterDialog extends ModalRoute<void> { List<Grades> mGradeList = []; List<Styles> mStyleList = []; List<Types> mTypeList = []; List<Specials> mSpecialList = []; FilterDialog(this.mGradeList, this.mStyleList, this.mTypeList, this

setState fires and render method gets hit, but nothing rerenders

眉间皱痕 提交于 2019-12-25 17:16:16
问题 I have this screen under a DrawerNavigator: class myScreen extends Component { state: Object; constructor(props) { super(props); this.getBeers(); this.state = { is_loading: true, beers: null, beers_ds: null, } } componentWillUpdate(nextProps: Object, nextState: Object) { if(!nextState.is_loading) { let ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 }); nextState.beers_ds = ds.cloneWithRows(nextState.beers); } } async getBeers() { let finalApiURL = API_BASE_URL; let

React setState in a map function

Deadly 提交于 2019-12-25 11:59:42
问题 I cannot wrap my head around the issue below. The issue relates to the asynchronous setState dimension. Usually I use the callback, but doesn't seem appropriate here. My goal is to create a state (that I will be able to sort) which is obtained by iterating on different states which are themselves created in a map. The function below calls my different methods, the ones we're interested in are the 2 last ones. getUserPoints and sortArrayforUserRank . getPlayersByUser = () => { database .ref(

React setState in a map function

流过昼夜 提交于 2019-12-25 11:58:45
问题 I cannot wrap my head around the issue below. The issue relates to the asynchronous setState dimension. Usually I use the callback, but doesn't seem appropriate here. My goal is to create a state (that I will be able to sort) which is obtained by iterating on different states which are themselves created in a map. The function below calls my different methods, the ones we're interested in are the 2 last ones. getUserPoints and sortArrayforUserRank . getPlayersByUser = () => { database .ref(

React: state not updating on first click

旧街凉风 提交于 2019-12-25 00:18:44
问题 I am working on a shopping cart sample. On each click, I am adding an object of the project to the Cart array. When I click the add cart button the first time, it doesn't update the Cart, but it updates on the second time. Although, when I click the viewCart button in the render's return statement, it shows the accurate number of items in the cart. See my code below: I need to be able to see the accurate number of items in the cart without clicking the viewCart button. The products come from

How to setState to answer from APi and use map

筅森魡賤 提交于 2019-12-25 00:08:49
问题 Im trying to create recipes searcher. In App.js I receive query from search input from another component and I want to setState to answer from APi. Console.log from callback in setState shows updated state but the state is not updated. I need setState updaed so I can use map on it and display list of recipes in render . It gives me error map is not a function because this.state.recipesList is still empty. Anyone can help me ? class App extends Component { state = { query: "", recipesList: []

Set state based on an a property present in array of objects : React+Typescript

孤街浪徒 提交于 2019-12-24 18:23:20
问题 I want to set state in react based on property that is present in the array of objects. Code Sandbox that looks similar : https://codesandbox.io/s/sleepy-lamarr-0sbdz This submit function is present as submitSelection() inside SelectComponent.tsx where I have console logged the state in the question . It is identical I have a state object that looks this like this: this state = { columns : [ {Header: ƒ, accessor: "firstName",show: true}, {Header: ƒ, accessor: "status", show: true}, {Header: ƒ

Flutter Set State onPressed on RaisedButton

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 15:29:07
问题 I am building a quiz app which reveals the explanation for the correct answer after the user submits their chosen answer. There are two buttons on the layout -- "Next Question" & "Submit Answer." In the initial state, the "Next Question" button is subtle as it is not clickable and only the "Submit Answer" buttons is clickable. Click Here to View the Layout of the Initial State When the "Submit Answer" button is clicked, two actions should happen: 1. The "Submit Answer" button then becomes

Row level operations on react-table: React Js

这一生的挚爱 提交于 2019-12-24 08:03:07
问题 I am trying to implement a feature where in on click of each row, I need to get the info of the row that is been clicked and corresponding row color should be changed to something else. And when I select multiple rows using Ctrl+mouse-click the corresponding rows color should also get changed, and need to get the info of corresponding rows in the form of array. I need to have a common getTrProps function that should implement both of this . Can someone help me out with this Codesandbox: https