so I have a rendered list which was created from an array and each element in the list has a menu button which displays a modal for each element, now the problem is if i click on the button of index 0 instead of showing for only index 0 it show for all, same thing for all other indexes
import React, {useState} from 'react'
import ListModal from './listModal';
export const Todo = ({ Todos, deleteItem }) => {
const [show, setshow] = useState(false);
const unshow = () => {
setshow(current => !current)
}
return (
<ul>
{
Todos.map((item, index) => (
<li key={index}>
<button className="deleteBoard" onClick={unshow}>•••</button>
<span>{item}</span>
<ListModal value = {item} show={show} unshow = {unshow} />
</li>
))
}
</ul>
);
};
ListModal is set to display:"none" so when i click the button it displays list modal vice versa
import React, { useState } from 'react'
import firebase from 'firebase/app';
import { db } from '../Firebase/Firebase';
import { useRouteMatch } from 'react-router-dom';
const ListModal = ({ value, show, unshow }) => {
const [text, settext] = useState(value)
const styles = {
display: show ? 'flex' : 'none'
}
const textChange = (e) => {
settext(e.target.value)
}
return (
<div className="listModal" style={styles}>
<div className="listContent">
<textarea value={text} rows="6" onChange={textChange}></textarea>
<button>Save</button>
<button onClick={unshow}>Cancel</button>
</div>
<div className="listOption">
<ul>
<li onClick={() => {deleteItem(value);moveCard()}}>Delete</li>
</ul>
</div>
</div>
)
}
export default ListModal
Thanks in advance, I don't mind rewriting please just help me out. thanks