Skip to content
Advertisement

onclick changes all mapped items instead of just one

I have a problem where I am trying to click on a certain div being returned by my backend and update it. I am trying to have it setup so that you click edit and the blogTitle and blogBody become input bars where you type in the new title and new body. In my code you can see an update that works and one that does not. The problem with the one that does not is that when I hit edit all blogBody’s and blogTitle’s become input bars instead of just one.

This 5 second of the issue video might make more sense than my explanation.

Now in my code this mainly deals with the following:

JavaScript

Here is the full code:

JavaScript

Now I understand why it is doing this, I just cannot think through the logic of getting my edit button to only edit one at a time. Also I understand the update will not work once I fix this, I am trying to solve this problem of editing 1 at a time first before setting it up how the other update one is.

Edit: so far I received one dislike and no comments I re read through this and realized it lacks a bit of focus thus made the code simpler:

JavaScript

This is all thats needed to work with to solve the issue at hand which is edit one at a time instead of all of them. Leaving the op for reference.

Advertisement

Answer

Have a component for each element so they each have their own unique prompt

For example,

//Element.js

JavaScript

//App.js

Now in the body return of your main file you could just do this

First import import Element from "./Element"; Then add the new component with specified props

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement