Skip to content

Instantly share code, notes, and snippets.

@dbanksdesign
Created April 22, 2022 18:29
Show Gist options
  • Save dbanksdesign/a92aab364b9eb850569f57855008d6cc to your computer and use it in GitHub Desktop.
Save dbanksdesign/a92aab364b9eb850569f57855008d6cc to your computer and use it in GitHub Desktop.
Amplify Studio collection item passing
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