File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { useState , useEffect } from 'react' ;
2-
3- export function useReleaseHistory ( ) {
4- const releasesURL = 'https://nodejs.org/dist/index.json' ;
5- const [ releaseHistory , setReleaseHistory ] = useState ( [ ] ) ;
6- useEffect ( ( ) => {
7- const fetchData = async ( ) => {
8- const result = await fetch ( releasesURL ) . then ( data => data . json ( ) ) ;
9- setReleaseHistory ( result ) ;
10- } ;
11- fetchData ( ) ;
12- } , [ ] ) ;
13-
14- return releaseHistory ;
15- }
1+ export { useApiData } from './useApiDocs' ;
2+ export { useReleaseHistory } from './useReleaseHistory' ;
Original file line number Diff line number Diff line change 1+ import { useState , useEffect } from 'react' ;
2+
3+ // TODO: Flesh out API types.
4+ /* tslint:disable */
5+ interface APIResponse {
6+ classes : any [ ] ;
7+ globals : any [ ] ;
8+ methods : any [ ] ;
9+ miscs : any [ ] ;
10+ modules : any [ ] ;
11+ }
12+ /* tslint:enable */
13+
14+ export function useApiData ( version : string ) : APIResponse {
15+ const [ apiData , setApiData ] = useState < APIResponse > ( {
16+ classes : [ ] ,
17+ globals : [ ] ,
18+ methods : [ ] ,
19+ miscs : [ ] ,
20+ modules : [ ] ,
21+ } ) ;
22+
23+ useEffect ( ( ) => {
24+ const fetchData = async ( ) => {
25+ const res = await window . fetch (
26+ `https://nodejs.org/dist/${ version } /docs/api/all.json`
27+ ) ;
28+ setApiData ( ( await res . json ( ) ) as APIResponse ) ;
29+ } ;
30+ fetchData ( ) ;
31+ } , [ ] ) ;
32+
33+ return apiData ;
34+ }
Original file line number Diff line number Diff line change 1+ import { useState , useEffect } from 'react' ;
2+
3+ export function useReleaseHistory ( ) {
4+ const releasesURL = 'https://nodejs.org/dist/index.json' ;
5+ const [ releaseHistory , setReleaseHistory ] = useState ( [ ] ) ;
6+ useEffect ( ( ) => {
7+ const fetchData = async ( ) => {
8+ const result = await fetch ( releasesURL ) . then ( data => data . json ( ) ) ;
9+ setReleaseHistory ( result ) ;
10+ } ;
11+ fetchData ( ) ;
12+ } , [ ] ) ;
13+
14+ return releaseHistory ;
15+ }
Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import { useApiData } from '../hooks' ;
23import Hero from '../components/hero' ;
34import Layout from '../components/layout' ;
45
56export default ( ) => {
67 const title = 'API Docs' ;
78 const description = 'Come learn yourself something.' ;
9+ const apiData = useApiData ( 'v12.9.1' ) ;
810
911 return (
1012 < Layout title = { title } description = { description } >
1113 < Hero title = { title } />
1214 < article style = { { width : '100%' } } className = "article-reader" >
15+ < nav >
16+ < ul >
17+ { apiData . modules . map ( module => (
18+ < li key = { module . name } > { module . displayName } </ li >
19+ ) ) }
20+ </ ul >
21+ </ nav >
1322 < p > Welcome to the API Page!</ p >
1423 </ article >
1524 </ Layout >
You can’t perform that action at this time.
0 commit comments