generated from Daydreamer-riri/starter-lib
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add example of load JSON file
- Loading branch information
1 parent
d0b9b8b
commit b245213
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"key": "THIS IS A TEST JSON" | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useLoaderData } from 'react-router-dom' | ||
|
||
export default function Docs() { | ||
const json = useLoaderData() as typeof import('../docs/test.json') | ||
|
||
return ( | ||
<div>{json.key}</div> | ||
) | ||
} | ||
|
||
export const Component = Docs | ||
|
||
export const entry = 'src/pages/json.tsx' | ||
|
||
export async function loader() { | ||
// If you use `import('../docs/test.json?raw')`, it will return a JSON string. | ||
const json = (await import('../docs/test.json')).default | ||
|
||
return json | ||
} |