Last active
August 20, 2021 15:22
-
-
Save natafaye/26608ab9f2e5d2d6fc679dc263027456 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export default function Note() { // creating a function | |
const match = useRouteMatch(); // calling a function and saving it in a variable | |
const { noteId } = useParams(); | |
const note = useSelector(state => state.notes.find(n => n.id === noteId)); // calling a function with a parameter | |
return ( // returning something from a function | |
<div className="container mt-3"> | |
{ (!note) ? <Redirect to="/notfound"/> : | |
<Switch> | |
<Route path={`${match.path}/edit`}> | |
<NoteForm key={note.id} note={note} /> | |
</Route> | |
<Route path={`${match.path}`}> | |
<NoteView key={note.id} note={note} /> | |
</Route> | |
</Switch> | |
} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment