Skip to content

Instantly share code, notes, and snippets.

@natafaye
Last active August 20, 2021 15:22
Show Gist options
  • Save natafaye/26608ab9f2e5d2d6fc679dc263027456 to your computer and use it in GitHub Desktop.
Save natafaye/26608ab9f2e5d2d6fc679dc263027456 to your computer and use it in GitHub Desktop.
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