Controlled Input onChange Event Fires Only Once - ReactGetting the ID of the element that fired an eventHTML text input allow only numeric inputHow can I trigger an onchange event manually?Ajax request returns 200 OK, but an error event is fired instead of successWhy does JavaScript only work after opening developer tools in IE once?How do I view events fired on an element in Chrome DevTools?OnChange event using React JS for drop downHow get value datapicker in react toobox custom?Radio Input onChange only fires once?ReactJS: Need to change card styling using onClick function
What are the requirements for a river delta to form?
Game artist computer workstation set-up – is this overkill?
The origin of list data structure
Can the Tidal Wave spell trigger a vampire's weakness to running water?
Where are the "shires" in the UK?
What Kind of Wooden Beam is this
Endgame puzzle: How to avoid stalemate and win?
What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?
Where to draw the line between quantum mechanics theory and its interpretation(s)?
My first C++ game (snake console game)
Is any special diet an effective treatment of autism?
Why are oscilloscope input impedances so low?
Why did WWI include Japan?
Page count conversion from single to double-space for submissions
Disabling quote conversion in docstrings
My large rocket is still flipping over
Why is my arithmetic with a long long int behaving this way?
Sheared off exhasut pipe: How to fix without a welder?
Should I simplify my writing in a foreign country?
In linear regression why does regularisation penalise the parameter values as well?
weird pluperfect subjunctive in Eutropius
Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?
How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?
Piano: quaver triplets in RH v dotted quaver and semiquaver in LH
Controlled Input onChange Event Fires Only Once - React
Getting the ID of the element that fired an eventHTML text input allow only numeric inputHow can I trigger an onchange event manually?Ajax request returns 200 OK, but an error event is fired instead of successWhy does JavaScript only work after opening developer tools in IE once?How do I view events fired on an element in Chrome DevTools?OnChange event using React JS for drop downHow get value datapicker in react toobox custom?Radio Input onChange only fires once?ReactJS: Need to change card styling using onClick function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Only one key press is registered, then the input loses focus however I can click back into the component and add ... one character. State is updated.
Since the child components are state-less I assumed that just passing the handlers down as props as described in the docs would be sufficient, but everything from changing the binding for the method to adding a constructor have yielded the same results. I can usually find an answer on the site but no luck this time.
const list = [
id : 0,
title : "Went well",
showCard : false,
cards : [],
color : "pink"
,
id : 1,
title : "To Improve",
showCard : false,
cards : [],
color : "yellow"
,
id : 2,
title : "Action Items",
showCard : false,
cards : [],
color : "blue"
]
class App extends Component
state = list : list, usrInpt : ""
handleChange = e => this.setState(usrInpt:e.target.value)
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
this.setState(list:updatedList)
//this.setState(this.state.list[e.target.id].cards = [...this.state.list[e.target.id].cards,"pp"])
render()
return (
<div className="App">
<h2>Metro Board</h2>
<ul className="container">
this.state.list.map((item) =>
<List key=(Math.random() * 1) text=item.title
id=item.id cards=item.cards color=item.color
usrInpt=this.state.usrInpt add=this.add handleChange=this.handleChange/>
)
</ul>
</div>
)
const List = (props) =>
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <ListItem key=(Math.random() * 1)
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
const ListItem = (props) =>
console.log("card props and value",props)
return <li>
<div className="card" style=backgroundColor: props.color>
<textarea type="text"
className="card"
placeholder="Enter text here"
value=props.usrInpt
onChange=e => props.handleChange(e)>
</textarea>
<div><a className="ltCtl" href="./logo" onClick=e => console.log(e)><</a>
<a className="clCtl" href="./logo" onClick=e => console.log(e)>x</a>
<a className="rtCtl" href="./logo" onClick=e => console.log(e)>></a>
</div>
</div>
</li>
Both List && ListItem are separate files... Any help would be great. Thanks.
javascript reactjs
add a comment |
Only one key press is registered, then the input loses focus however I can click back into the component and add ... one character. State is updated.
Since the child components are state-less I assumed that just passing the handlers down as props as described in the docs would be sufficient, but everything from changing the binding for the method to adding a constructor have yielded the same results. I can usually find an answer on the site but no luck this time.
const list = [
id : 0,
title : "Went well",
showCard : false,
cards : [],
color : "pink"
,
id : 1,
title : "To Improve",
showCard : false,
cards : [],
color : "yellow"
,
id : 2,
title : "Action Items",
showCard : false,
cards : [],
color : "blue"
]
class App extends Component
state = list : list, usrInpt : ""
handleChange = e => this.setState(usrInpt:e.target.value)
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
this.setState(list:updatedList)
//this.setState(this.state.list[e.target.id].cards = [...this.state.list[e.target.id].cards,"pp"])
render()
return (
<div className="App">
<h2>Metro Board</h2>
<ul className="container">
this.state.list.map((item) =>
<List key=(Math.random() * 1) text=item.title
id=item.id cards=item.cards color=item.color
usrInpt=this.state.usrInpt add=this.add handleChange=this.handleChange/>
)
</ul>
</div>
)
const List = (props) =>
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <ListItem key=(Math.random() * 1)
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
const ListItem = (props) =>
console.log("card props and value",props)
return <li>
<div className="card" style=backgroundColor: props.color>
<textarea type="text"
className="card"
placeholder="Enter text here"
value=props.usrInpt
onChange=e => props.handleChange(e)>
</textarea>
<div><a className="ltCtl" href="./logo" onClick=e => console.log(e)><</a>
<a className="clCtl" href="./logo" onClick=e => console.log(e)>x</a>
<a className="rtCtl" href="./logo" onClick=e => console.log(e)>></a>
</div>
</div>
</li>
Both List && ListItem are separate files... Any help would be great. Thanks.
javascript reactjs
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try usingkey=item.id
when you are mapping arrays
– miyu
Mar 23 at 3:30
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52
add a comment |
Only one key press is registered, then the input loses focus however I can click back into the component and add ... one character. State is updated.
Since the child components are state-less I assumed that just passing the handlers down as props as described in the docs would be sufficient, but everything from changing the binding for the method to adding a constructor have yielded the same results. I can usually find an answer on the site but no luck this time.
const list = [
id : 0,
title : "Went well",
showCard : false,
cards : [],
color : "pink"
,
id : 1,
title : "To Improve",
showCard : false,
cards : [],
color : "yellow"
,
id : 2,
title : "Action Items",
showCard : false,
cards : [],
color : "blue"
]
class App extends Component
state = list : list, usrInpt : ""
handleChange = e => this.setState(usrInpt:e.target.value)
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
this.setState(list:updatedList)
//this.setState(this.state.list[e.target.id].cards = [...this.state.list[e.target.id].cards,"pp"])
render()
return (
<div className="App">
<h2>Metro Board</h2>
<ul className="container">
this.state.list.map((item) =>
<List key=(Math.random() * 1) text=item.title
id=item.id cards=item.cards color=item.color
usrInpt=this.state.usrInpt add=this.add handleChange=this.handleChange/>
)
</ul>
</div>
)
const List = (props) =>
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <ListItem key=(Math.random() * 1)
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
const ListItem = (props) =>
console.log("card props and value",props)
return <li>
<div className="card" style=backgroundColor: props.color>
<textarea type="text"
className="card"
placeholder="Enter text here"
value=props.usrInpt
onChange=e => props.handleChange(e)>
</textarea>
<div><a className="ltCtl" href="./logo" onClick=e => console.log(e)><</a>
<a className="clCtl" href="./logo" onClick=e => console.log(e)>x</a>
<a className="rtCtl" href="./logo" onClick=e => console.log(e)>></a>
</div>
</div>
</li>
Both List && ListItem are separate files... Any help would be great. Thanks.
javascript reactjs
Only one key press is registered, then the input loses focus however I can click back into the component and add ... one character. State is updated.
Since the child components are state-less I assumed that just passing the handlers down as props as described in the docs would be sufficient, but everything from changing the binding for the method to adding a constructor have yielded the same results. I can usually find an answer on the site but no luck this time.
const list = [
id : 0,
title : "Went well",
showCard : false,
cards : [],
color : "pink"
,
id : 1,
title : "To Improve",
showCard : false,
cards : [],
color : "yellow"
,
id : 2,
title : "Action Items",
showCard : false,
cards : [],
color : "blue"
]
class App extends Component
state = list : list, usrInpt : ""
handleChange = e => this.setState(usrInpt:e.target.value)
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
this.setState(list:updatedList)
//this.setState(this.state.list[e.target.id].cards = [...this.state.list[e.target.id].cards,"pp"])
render()
return (
<div className="App">
<h2>Metro Board</h2>
<ul className="container">
this.state.list.map((item) =>
<List key=(Math.random() * 1) text=item.title
id=item.id cards=item.cards color=item.color
usrInpt=this.state.usrInpt add=this.add handleChange=this.handleChange/>
)
</ul>
</div>
)
const List = (props) =>
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <ListItem key=(Math.random() * 1)
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
const ListItem = (props) =>
console.log("card props and value",props)
return <li>
<div className="card" style=backgroundColor: props.color>
<textarea type="text"
className="card"
placeholder="Enter text here"
value=props.usrInpt
onChange=e => props.handleChange(e)>
</textarea>
<div><a className="ltCtl" href="./logo" onClick=e => console.log(e)><</a>
<a className="clCtl" href="./logo" onClick=e => console.log(e)>x</a>
<a className="rtCtl" href="./logo" onClick=e => console.log(e)>></a>
</div>
</div>
</li>
Both List && ListItem are separate files... Any help would be great. Thanks.
javascript reactjs
javascript reactjs
asked Mar 23 at 3:16
kn0tkn0t
327
327
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try usingkey=item.id
when you are mapping arrays
– miyu
Mar 23 at 3:30
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52
add a comment |
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try usingkey=item.id
when you are mapping arrays
– miyu
Mar 23 at 3:30
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try using
key=item.id
when you are mapping arrays– miyu
Mar 23 at 3:30
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try using
key=item.id
when you are mapping arrays– miyu
Mar 23 at 3:30
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52
add a comment |
2 Answers
2
active
oldest
votes
UPDATE:
I was able to reach out to a full time developer and it seems I screwed up by trying to make unique keys :
The key needs to be consistent, but in this case it is a different value every time
React uses the key when it IDs which element is focusing on, but in this case, it is different than the last render. So React does not know what to focus on. You can have unique keys if you use a string with the index of the loop in it, or if you use an ID that you store outside in the loop, like in state
It does need to be unique, but it also needs to be consistent.
So the code:
return (
<Card
key=Math.random() * 1 // <--- Don't!!
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt
/>
);
was causing React to lose track of what to render since the keys where changing with each render. The preferred method is using a string interpolation with an identifier and an index if a loop is used:
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <Card key=`card-column-$props.id-$i`
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
Which was also a comment made by @miyu ... which I did not test. Listen to your peers and mentors... you will not lose 12 hours chasing bugs. Thanks.
add a comment |
state
is non-hierarchical. Meaning, when you update a child object of your state but the parent object is not updated, then react will not trigger componentDidChange
.
Try adding a counter which gets updated when the list is updated.
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
let counter = this.state.counter
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310274%2fcontrolled-input-onchange-event-fires-only-once-react%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
UPDATE:
I was able to reach out to a full time developer and it seems I screwed up by trying to make unique keys :
The key needs to be consistent, but in this case it is a different value every time
React uses the key when it IDs which element is focusing on, but in this case, it is different than the last render. So React does not know what to focus on. You can have unique keys if you use a string with the index of the loop in it, or if you use an ID that you store outside in the loop, like in state
It does need to be unique, but it also needs to be consistent.
So the code:
return (
<Card
key=Math.random() * 1 // <--- Don't!!
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt
/>
);
was causing React to lose track of what to render since the keys where changing with each render. The preferred method is using a string interpolation with an identifier and an index if a loop is used:
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <Card key=`card-column-$props.id-$i`
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
Which was also a comment made by @miyu ... which I did not test. Listen to your peers and mentors... you will not lose 12 hours chasing bugs. Thanks.
add a comment |
UPDATE:
I was able to reach out to a full time developer and it seems I screwed up by trying to make unique keys :
The key needs to be consistent, but in this case it is a different value every time
React uses the key when it IDs which element is focusing on, but in this case, it is different than the last render. So React does not know what to focus on. You can have unique keys if you use a string with the index of the loop in it, or if you use an ID that you store outside in the loop, like in state
It does need to be unique, but it also needs to be consistent.
So the code:
return (
<Card
key=Math.random() * 1 // <--- Don't!!
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt
/>
);
was causing React to lose track of what to render since the keys where changing with each render. The preferred method is using a string interpolation with an identifier and an index if a loop is used:
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <Card key=`card-column-$props.id-$i`
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
Which was also a comment made by @miyu ... which I did not test. Listen to your peers and mentors... you will not lose 12 hours chasing bugs. Thanks.
add a comment |
UPDATE:
I was able to reach out to a full time developer and it seems I screwed up by trying to make unique keys :
The key needs to be consistent, but in this case it is a different value every time
React uses the key when it IDs which element is focusing on, but in this case, it is different than the last render. So React does not know what to focus on. You can have unique keys if you use a string with the index of the loop in it, or if you use an ID that you store outside in the loop, like in state
It does need to be unique, but it also needs to be consistent.
So the code:
return (
<Card
key=Math.random() * 1 // <--- Don't!!
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt
/>
);
was causing React to lose track of what to render since the keys where changing with each render. The preferred method is using a string interpolation with an identifier and an index if a loop is used:
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <Card key=`card-column-$props.id-$i`
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
Which was also a comment made by @miyu ... which I did not test. Listen to your peers and mentors... you will not lose 12 hours chasing bugs. Thanks.
UPDATE:
I was able to reach out to a full time developer and it seems I screwed up by trying to make unique keys :
The key needs to be consistent, but in this case it is a different value every time
React uses the key when it IDs which element is focusing on, but in this case, it is different than the last render. So React does not know what to focus on. You can have unique keys if you use a string with the index of the loop in it, or if you use an ID that you store outside in the loop, like in state
It does need to be unique, but it also needs to be consistent.
So the code:
return (
<Card
key=Math.random() * 1 // <--- Don't!!
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt
/>
);
was causing React to lose track of what to render since the keys where changing with each render. The preferred method is using a string interpolation with an identifier and an index if a loop is used:
return(
<li>
<h3>props.text</h3>
<ul className="stack">
<li><button id=props.id type="button" className="block" onClick=e =>props.add(e)>+</button></li>
props.cards.map((card,i)=>
console.log("card",card)
return <Card key=`card-column-$props.id-$i`
idx=i
color=props.color
handleChange=props.handleChange
usrInpt=props.usrInpt/>
)
</ul>
</li>
)
Which was also a comment made by @miyu ... which I did not test. Listen to your peers and mentors... you will not lose 12 hours chasing bugs. Thanks.
edited Mar 23 at 20:29
answered Mar 23 at 20:21
kn0tkn0t
327
327
add a comment |
add a comment |
state
is non-hierarchical. Meaning, when you update a child object of your state but the parent object is not updated, then react will not trigger componentDidChange
.
Try adding a counter which gets updated when the list is updated.
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
let counter = this.state.counter
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
add a comment |
state
is non-hierarchical. Meaning, when you update a child object of your state but the parent object is not updated, then react will not trigger componentDidChange
.
Try adding a counter which gets updated when the list is updated.
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
let counter = this.state.counter
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
add a comment |
state
is non-hierarchical. Meaning, when you update a child object of your state but the parent object is not updated, then react will not trigger componentDidChange
.
Try adding a counter which gets updated when the list is updated.
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
let counter = this.state.counter
state
is non-hierarchical. Meaning, when you update a child object of your state but the parent object is not updated, then react will not trigger componentDidChange
.
Try adding a counter which gets updated when the list is updated.
add = e =>
e.preventDefault()
let updatedList = this.state.list.map(obj =>
if(obj.id == e.target.id)
this.state.list[obj.id].cards.push(this.state.usrInpt)
return obj
)
console.log("uL",updatedList)
let counter = this.state.counter
answered Mar 23 at 4:22
Irene MitchellIrene Mitchell
443
443
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
add a comment |
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
Thank you for the reply, I had to work last night so I couldn't respond. I tried your code as written but the behavior still persists. I am unsure how to approach the problem from here, but I will continue to look for a solution.
– kn0t
Mar 23 at 15:27
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
I just checked the React developer tools in Chrome and the counter isn't being incremented. I'll start from there since it should update.
– kn0t
Mar 23 at 15:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310274%2fcontrolled-input-onchange-event-fires-only-once-react%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It would make it easier for others to help you if you could provide a more minimal example that only demonstrates your problem with little to none excess code.
– ChrisBrownie55
Mar 23 at 3:26
Randomly generating your keys might be causing problems with the render cycle. It looks like your data already has unique ids so try using
key=item.id
when you are mapping arrays– miyu
Mar 23 at 3:30
@miyu I tested that theory, it's not the source of the problem.
– ChrisBrownie55
Mar 23 at 4:00
@miyu You are correct, I saw your reply and didn't test it for myself. I apologize for that, it won't ever happen again. Thanks.
– kn0t
Mar 23 at 19:52