Created
April 22, 2022 18:29
-
-
Save dbanksdesign/a92aab364b9eb850569f57855008d6cc to your computer and use it in GitHub Desktop.
Amplify Studio collection item passing
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
import * as React from "react"; | |
import { Routes, Route, Link, useNavigate, useLocation } from "react-router-dom"; | |
import { Ampligram, AmpligramCollection } from './ui-components'; | |
const Home = () => { | |
let navigate = useNavigate(); | |
return ( | |
<div> | |
<AmpligramCollection | |
overrideItems={({ item, index }) => { | |
return { | |
onClick() { | |
navigate(`post/${item.id}`, {state: {post: item}}) | |
} | |
} | |
}} | |
/> | |
</div> | |
) | |
} | |
const PostDetail = () => { | |
let {state} = useLocation(); | |
return ( | |
<> | |
<Ampligram post={state.post} /> | |
</> | |
); | |
} | |
function App() { | |
return ( | |
<Routes> | |
<Route path="/" element={<Home />} /> | |
<Route path="post/:id" element={<PostDetail />} /> | |
</Routes> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment