Download react-query/examples/react/auto-refetching/src/pages/api/data.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 460 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/auto-refetching/src/pages/api/data.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/auto-refetching/src/pages/api/data.ts
-
curl -L -o data.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/auto-refetching/src/pages/api/data.ts
460 Bytes
| import type { NextApiRequest, NextApiResponse } from 'next' | |
| // an simple endpoint for getting current list | |
| let list = ['Item 1', 'Item 2', 'Item 3'] | |
| export default async ( | |
| req: NextApiRequest, | |
| res: NextApiResponse<typeof list>, | |
| ) => { | |
| if (req.query.add) { | |
| if (!list.includes(req.query.add)) { | |
| list.push(req.query.add) | |
| } | |
| } else if (req.query.clear) { | |
| list = [] | |
| } | |
| await new Promise((r) => setTimeout(r, 100)) | |
| res.json(list) | |
| } | |