Created
October 25, 2022 09:08
-
-
Save victorbruce/2f846febe77be12db8abd455ffe36874 to your computer and use it in GitHub Desktop.
using redux in a component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {useAppSelector, useAppDispatch} from "hooks" | |
import {selectNotes, removeNote} from "slice" | |
const HomePage = (): JSX.Element => { | |
const notes = useAppSelector(selectNotes); | |
const dispatch = useAppDispatch(); | |
const deleteNote = (noteId: string) => { | |
dispatch(removeNote(noteId)) | |
} | |
const renderNotes = notes.map((note) => ( | |
<div key={note.id}> | |
<h1>{note.title}</h1> | |
<p>{note.content}</p> | |
<button onClick={() => deleteNote(note.id)}>Delete Note</button> | |
</div> | |
)) | |
return ( | |
<div> | |
{renderNotes} | |
</div> | |
) | |
} | |
export default HomePage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment