This file contains 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 type { NextApiRequest, NextApiResponse } from 'next' | |
type Data = { | |
name: string | |
} | |
export default function handler( | |
req: NextApiRequest, | |
res: NextApiResponse<Data> | |
) { |
This file contains 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 type { NextApiRequest, NextApiResponse } from "next"; | |
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; | |
type HttpHandler = (request: NextApiRequest, response: NextApiResponse) => void; | |
interface RouteHandlerParams { | |
GET?: HttpHandler; | |
POST?: HttpHandler; | |
PUT?: HttpHandler; | |
DELETE?: HttpHandler; |
This file contains 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 { NextApiRequest, NextApiResponse } from "next"; | |
import { PrismaClient } from "@prisma/client"; | |
import config from "../config"; | |
export const SimpleGet = async ( | |
req: NextApiRequest, | |
res: NextApiResponse | |
) => { | |
return res.status(200).json({ message: "Hello World!" }); | |
}; |
This file contains 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 { RouteHandler, SimpleGet } from "handlers"; | |
import type { NextApiRequest, NextApiResponse } from "next"; | |
export default async function handler( | |
req: NextApiRequest, | |
res: NextApiResponse | |
) { | |
await RouteHandler(req, res, { | |
GET: SimpleGet | |
}); |
This file contains 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 { useRouter } from "next/router"; | |
const MessyRouter = () => { | |
const router = useRouter(); | |
const { organisation, workspace } = router.query; | |
const route1 = `/${organisation}/${workspace}/route-1` | |
const route2 = `/${organisation}/${workspace}/route-2`; | |
return ( |
This file contains 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 { useRouter } from "next/router"; | |
import { useEffect, useState } from "react"; | |
const PATH = "discovery"; | |
const useDiscoveryRouter = () => { | |
const [organisation, setOrganisation] = useState<string>(""); | |
const [workspace, setWorkspace] = useState<string>(""); | |
const router = useRouter(); |
This file contains 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 useDiscoveryRouter from "@/utils/routers/useDiscoveryRouter"; | |
const CleanRouter = () => { | |
const discoverRouter = useDiscoveryRouter(); | |
const extraLinks = ["discovery-1", "discovery-2", "discovery-3"].map( | |
(link) => ( | |
<li> | |
<a href={discoverRouter.editDiscovery(link)}></a> | |
</li> |
This file contains 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
interface ModalProps { | |
opened: boolean; | |
close: () => void; | |
} | |
const AppModal = (props: ModalProps) => { | |
return ( | |
<Modal opened={props.opened}> | |
{/* Modal content goes here */} | |
<button onClick={close}>close</button> |
This file contains 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 { useState } from "react"; | |
export interface BodyProps { | |
close: () => void; | |
} | |
interface UseModalProps { | |
Body: (props: BodyProps) => JSX.Element; | |
} |
This file contains 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 useModal from "@/components/modal"; | |
const App = () => { | |
const AppModal = useModal({ | |
Body: (props) => ( | |
<> | |
<h1>Hello from my modal!</h1> | |
<button onClick={props.close}>Close</button> | |
</> | |
), |
OlderNewer