does someone have an idea for a solution to the following problem? I would be really happy for some advice!
Here are some information to help understand what I'm about to do:
- there is a list where you can add your DIY projects
- when you click the edit button of a project, you can add some information to every project.
Link to the project: https://diy-project-planner.vercel.app/
My problem:
- when I write down a note within a project, it appears on every project instead of just the one I added the note to:
The Code of the edit page
const projects = useStore(state => state.projects);
const router = useRouter();
const {id} = router.query;
const entry = projects.find(entry => entry.id === String(id));
const notes = useStore(state => state.notes);
const addNote = useStore(state => state.addNote);
const [note, setNote] = useState('');
if (!entry) {
return;
}
return (
<Layout>
<h1>{entry.name}</h1>
<h2>Notizen</h2>
<form
onSubmit={event => {
event.preventDefault();
addNote(note);
}}
>
<StyledInputField
type="text"
value={note}
onChange={event => {
setNote(event.target.value);
}}
/>
<StyledButton type="submit">add</StyledButton>
{notes.map(note => {
return <p key={note.id}>{note.name}</p>;
})}
</form>{' '}
</Layout>
);
}
The code of useStore (Global State Handling with Zustand)
const useStore = create(set => ({
projects: [
{name: 'Pflanzenleiter', id: nanoid(), isDone: false},
{name: 'Bilderrahmen', id: nanoid(), isDone: false},
],
addProject: name => {
set(state => {
return {
projects: [...state.projects, {id: nanoid(), name, isDone: false}],
};
});
},
notes: [],
addNote: name => {
set(state => {
return {
notes: [...state.notes, {id: nanoid(), name}],
};
});
},
Thanks a lot in advance for your help! :-)