setstate

Input value not Updating after setState change… Increment and Decrement

让人想犯罪 __ 提交于 2021-02-11 15:14:35
问题 I have these increment and decrement buttons that will add or subtract. I will import the default values from props and then want to allow the user to make adjustments. So when I update the state (series) for the appropriate group it appears to update just fine... but the input value remains '14' in the HTML although I have it set to value={this.state[mppt_number].series} . Shouldn't it automatically update when the state changes? It probably has to do with the [mppt_number] variable.... if

React setState and await

我的梦境 提交于 2021-02-11 14:34:54
问题 While the functional setState() is recommended when the current state is being used, the function still cannot be async. How could we develop a function that uses the state, calls a REST API and changes the state right after? This is the original function, that disregards the async behavior of setState. onSortColumnChanged = (sortColumn) => async (event) => { const prev = this.state; ​ const searchParams = { ...prev.params, sortColumn: sortColumn }; ​ const result = await this.callSearch

Passing a function to State in React

陌路散爱 提交于 2021-02-11 12:24:25
问题 I am new to React and have a question regarding passing down functions in a state. I have a couple of 'sorting functions' in my util folder, which look like this: export const sortColdestSummerCountries = (filteredCountries) => { return filteredCountries.sort( (a, b) => a.avsummertemp20802099 - b.avsummertemp20802099 ); }; and a few others: sortHighestSummerTemp, sortLargestIncreaseHotDays, sortColdestSummerCountries, sortMostColdDays, sortWorstAffectedCountries which pretty much look similar

How to use map function for hooks useState properties dynamically

孤街浪徒 提交于 2021-02-10 04:59:50
问题 My question is almost the same as this one. In this case, the person has a map of states created in a hard coded way: const App = props => { const [state, changeState] = useState({ name: "", eventTitle: "", details: "", list: "", toggleIndex: "", editName: "", editEventTitle: "", editDetails: "", }); The difference is that I want to create those states dynamically, receiving them from another component. I tried something like this but it obviously did not work: const App = props => { const

How to use map function for hooks useState properties dynamically

。_饼干妹妹 提交于 2021-02-10 04:58:09
问题 My question is almost the same as this one. In this case, the person has a map of states created in a hard coded way: const App = props => { const [state, changeState] = useState({ name: "", eventTitle: "", details: "", list: "", toggleIndex: "", editName: "", editEventTitle: "", editDetails: "", }); The difference is that I want to create those states dynamically, receiving them from another component. I tried something like this but it obviously did not work: const App = props => { const

React batch updates for multiple setState() calls inside useEffect hook

梦想与她 提交于 2021-02-06 20:09:24
问题 On this answer by Dan Abramov here on SO, I've found out the following: Does React keep the order for state updates? Currently (React 16 and earlier), only updates inside React event handlers are batched by default. There is an unstable API to force batching outside of event handlers for rare cases when you need it. He also mentions that in this Github issue: https://github.com/facebook/react/issues/10231#issuecomment-316644950 In current release, they will be batched together if you are

React batch updates for multiple setState() calls inside useEffect hook

别等时光非礼了梦想. 提交于 2021-02-06 19:58:30
问题 On this answer by Dan Abramov here on SO, I've found out the following: Does React keep the order for state updates? Currently (React 16 and earlier), only updates inside React event handlers are batched by default. There is an unstable API to force batching outside of event handlers for rare cases when you need it. He also mentions that in this Github issue: https://github.com/facebook/react/issues/10231#issuecomment-316644950 In current release, they will be batched together if you are

How to disable only selected button onClick inside .map() function of REACT js

南楼画角 提交于 2021-01-29 10:03:19
问题 I have shopping Application in REACT js. Im displaying all products using .map() function, and also showing "ADD to CART" button infront of each product. When ADD to Cart btn is clicked, it adds the clicked product ID in local storage then I display these selected products in Shopping Cart by retrieving IDs from localStorage . It all works fine . Now what I wanted is to disable the "ADD to Cart" button(for selected product only) when its clicked Once. I did it by setting state but it actually

Setstate for statless widget dropdownButton from a stateful parent

半城伤御伤魂 提交于 2021-01-29 09:53:10
问题 I have three widgets first one is LightBulb(stateless) that have some color properties. The second one is widget named as LightColorSelector(stateless) that has a DropdownMenu with string type items Red , Green and Blue . And, the third class is Classroom(stateful widget) which is the parent of that two classes. My aim is to set the states from that class. I need to set a list of that three colors inside the Classroom , when someone clicks on one of the LightColorSelector items the LightBulb

Updating React state as a 2d array?

送分小仙女□ 提交于 2021-01-29 05:39:44
问题 Given this 2d array React state, this.state = board: [ [null, null, null, null], [null, {id: 21, canSelect: false}, null, null], [null, {id: 42, canSelect: false}, null, null], [null, null, null, null] ] } I have 3 main questions regarding using setState to update this state: 1) How would I target a specific index within this 2d array state in React? Something like board[1][1]: {newObject} ? 2) How would I update only the "canSelect" values for each? 3) If there were an unknown number of