Timeline for Reactjs - add/remove item from array and store using checkbox
Current License: CC BY-SA 4.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 18, 2018 at 12:13 | history | edited | John | CC BY-SA 4.0 |
deleted 67 characters in body
|
Jun 15, 2018 at 18:33 | history | edited | John | CC BY-SA 4.0 |
deleted 562 characters in body
|
S Jun 15, 2018 at 16:16 | history | suggested | Christopher Moore |
removed unnecessary tags
|
|
Jun 15, 2018 at 15:26 | answer | added | Mike B. | timeline score: 1 | |
Jun 15, 2018 at 14:54 | comment | added | Mike B. |
It looks like you're modifying the state directly (const removeAccountState = this.state and removeAccountState.accounts = filteredAccounts ), then calling setState after. Since setState is asynchronous, could that be causing your state to get out of sync between calls? Also in toggleChange you are updating just the checkboxes state, but in saveAccount you are updating the entire state (accounts and checkboxes), possibly overwriting your earlier checkboxes-only update?
|
|
Jun 15, 2018 at 14:36 | review | Suggested edits | |||
S Jun 15, 2018 at 16:16 | |||||
Jun 15, 2018 at 14:36 | comment | added | John | Just updated my question with toggleChange() | |
Jun 15, 2018 at 14:35 | history | edited | John | CC BY-SA 4.0 |
added 346 characters in body
|
Jun 15, 2018 at 14:34 | comment | added | Christopher Moore | Thanks, you're trying to store the state of accounts in local state and in redux. In my experience this leads to problems when things get out of sync. Either stick to 100% redux, or 100% local state. Don't try and mix the two | |
Jun 15, 2018 at 14:33 | comment | added | Kirill Matrosov | Maybe, your actions and state are not synchronized. Add please toggleChange code also. | |
Jun 15, 2018 at 14:30 | comment | added | John | Just updated my question with my actions. In saveAccount I have a condition, only add if checkbox checked and only remove if checkbox unchecked if(this.props.checkboxStatus[i].checked === true)( ...) else(){ ... } | |
Jun 15, 2018 at 14:25 | history | edited | John | CC BY-SA 4.0 |
added 580 characters in body
|
Jun 15, 2018 at 14:24 | comment | added | Christopher Moore |
Could you show your actions and how you're dispatching them? Also, in saveAccount regardless of the checked state you're adding the account, is that correct? this.props.addAccount(removeAccountState.accounts)
|
|
Jun 15, 2018 at 14:07 | history | asked | John | CC BY-SA 4.0 |