Skip to content

Commit

Permalink
json server stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jul 14, 2024
1 parent d3a58c4 commit 288bbf2
Show file tree
Hide file tree
Showing 11 changed files with 4,565 additions and 276 deletions.
3 changes: 1 addition & 2 deletions apps/1-vite-componentdidmount/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export class HomePage extends Component<{}, HomePageState> {
this.setState({ isFetchingPosts: true });

try {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);
const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
const fetchedPosts = (await response.json()) as IPost[];
this.setState({ posts: fetchedPosts });
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions apps/2-vite-useeffect/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export function HomePage() {
}
setIsFetchingPosts(true);
try {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);
const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
const fetchedPosts = (await response.json()) as IPost[];
setPosts(fetchedPosts);
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions apps/3-vite-reactquery/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export function HomePage() {
} = useQuery({
queryKey: ["posts"],
queryFn: async () => {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);

const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
return response.json() as Promise<IPost[]>;
},
});
Expand Down
3 changes: 1 addition & 2 deletions apps/4-nextjs-ssr/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ const HomePage = ({ posts, error }: HomePageProps) => {

export const getServerSideProps: GetServerSideProps = async () => {
try {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);
const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
const fetchedPosts = (await response.json()) as IPost[];

return {
Expand Down
3 changes: 1 addition & 2 deletions apps/5-remix-ssr/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ interface LoaderData {

export const loader: LoaderFunction = async () => {
try {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);
const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
const fetchedPosts = (await response.json()) as IPost[];

return json<LoaderData>({
Expand Down
3 changes: 1 addition & 2 deletions apps/6-nextjs-rsc/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import Link from "next/link";
import { Suspense } from "react";

const fetchPosts = async () => {
const fetchUrl = new URL(`https://jsonplaceholder.typicode.com/posts`);
const fetchUrl = new URL(`http://localhost:3333/posts`);
const response = await fetch(fetchUrl.href);
await new Promise((resolve) => setTimeout(resolve, 1000)); // Simulate slow network
const fetchedPosts = (await response.json()) as IPost[];
return fetchedPosts;
};
Expand Down
Loading

0 comments on commit 288bbf2

Please sign in to comment.