Prosiłbym o wskazówkę jak match id buttona z id textarea , by wyświetlany mógł być tylko 1 note w tym samym czasie. I wchodził jakby na miejsce poprzednika(z innymi wartościami)[I przełączać między nimi]
KOD PARENT
import { react, useState } from "react";
import Notes from "./Notes";
function Notepad() {
const [noteID, setNoteID] = useState(0);
const [visible] = useState(false);
function handleSubmit(e) {
e.preventDefault();
setNoteID((prevValue) => prevValue + 1);
}
function currentNote(id) {
}
return (
<div>
<button onClick={handleSubmit}>New Note</button>
{[...Array(noteID).keys()].map((item) => {
return <Notes key={item} noteID={item} selected={currentNote(item)} show={visible} />;
})}
</div>
);
}
export default Notepad;
Child Componetnt
import { useState } from "react";
function Notes(props) {
const [Shown, setShown] = useState(props.show);
function toggle(e) {
e.preventDefault();
setShown(!Shown);
}
return (
<form action="return false" key={props.noteID} onClick={props.selected}>
{Shown ? <textarea key={props.noteID} placeholder="Text Goes Here" name="textarea" /> : null}
<button key={`Note` + props.noteID} type="submit" name="button" onClick={toggle}>
Note {props.noteID + 1}
</button>
</form>
);
}
export default Notes;