Skip to content

Instantly share code, notes, and snippets.

@victorbruce
Created October 25, 2022 09:08
Show Gist options
  • Save victorbruce/2f846febe77be12db8abd455ffe36874 to your computer and use it in GitHub Desktop.
Save victorbruce/2f846febe77be12db8abd455ffe36874 to your computer and use it in GitHub Desktop.
using redux in a component
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