-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(v2): add docs on useful client api #1890
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12e94ad
docs(v2): add docs on useful client api
endiliey 053614a
Update docusaurus-core.md
yangshun f414391
Update website/docs/docusaurus-core.md
endiliey 3267b90
Update website/docs/docusaurus-core.md
endiliey 4c58990
Update website/docs/docusaurus-core.md
endiliey f985f10
Update website/docs/docusaurus-core.md
endiliey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,16 +1,145 @@ | ||
--- | ||
id: docusaurus-core | ||
title: Docusaurus Core | ||
title: Docusaurus Core API | ||
--- | ||
|
||
_This section is a work in progress._ | ||
Docusaurus provides some API on client that can be helpful when building your site. | ||
|
||
<!-- | ||
## `<Head />` | ||
|
||
Mention Docusaurus core APIs here, such as `<Link />`, `<Head />`, `prefetch`, etc. | ||
This reusable React component will manage all of your changes to the document head. It takes plain HTML tags and outputs plain HTML tags and is beginner-friendly. It is a wrapper around [React Helmet](https://github.com/nfl/react-helmet). | ||
|
||
References | ||
--- | ||
- [source code](/packages/docusaurus/README.MD) | ||
Usage Example: | ||
|
||
```jsx | ||
import React from 'react'; | ||
import Head from '@docusaurus/Head'; | ||
|
||
const MySEO = () => ( | ||
<> | ||
<Head> | ||
<meta property="og:description" content="My custom description" /> | ||
<meta charSet="utf-8" /> | ||
<title>My Title</title> | ||
<link rel="canonical" href="http://mysite.com/example" /> | ||
</Head> | ||
</> | ||
); | ||
``` | ||
|
||
Nested or latter components will override duplicate usages: | ||
|
||
```jsx | ||
<Parent> | ||
<Head> | ||
<title>My Title</title> | ||
<meta name="description" content="Helmet application" /> | ||
</Head> | ||
|
||
<Child> | ||
<Head> | ||
<title>Nested Title</title> | ||
<meta name="description" content="Nested component" /> | ||
</Head> | ||
</Child> | ||
</Parent> | ||
``` | ||
|
||
Outputs | ||
|
||
```html | ||
<head> | ||
<title>Nested Title</title> | ||
<meta name="description" content="Nested component" /> | ||
</head> | ||
``` | ||
|
||
## `<Link />` | ||
|
||
This component enables linking to internal pages as well as a powerful performance feature called preloading. Preloading is used to prefetch resources so that the resources are fetched by the time the user navigates with this component. We use an `IntersectionObserver` to fetch a low-priority request when the `<Link>` is in the viewport and then use an `onMouseOver` event to trigger a high-priority request when it is likely that a user will navigate to the requested resource. | ||
|
||
The component is a wrapper around react-router’s `<NavLink>` component that adds useful enhancements specific to Docusaurus. All props are passed through to react-router’s `<Link>` component. | ||
endiliey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
import React from 'react'; | ||
import Link from '@docusaurus/Link'; | ||
|
||
const Page = () => ( | ||
<div> | ||
<p> | ||
Check out my <Link to="/blog">blog</Link>! | ||
</p> | ||
<p> | ||
{/* Note that external links still use `a` tags. */} | ||
Follow me on <a href="https://twitter.com/docusaurus">Twitter</a>! | ||
</p> | ||
</div> | ||
); | ||
``` | ||
|
||
### `to`: string | ||
|
||
A string representation of the `<Link>` location, created by concatenating the location's pathname, search, and hash properties. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This description is confusing to me, even though it was taken from RR docs.
endiliey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```jsx | ||
<Link to="/courses" /> | ||
``` | ||
|
||
### `activeClassName`: string | ||
|
||
The class to give the `<Link>` when it is active. The default given class is `active`. This will be joined with the `className` prop. | ||
|
||
```jsx | ||
<Link to="/faq" activeClassName="selected"> | ||
FAQs | ||
</Link> | ||
``` | ||
|
||
## `useDocusaurusContext` | ||
|
||
React Hooks to access Docusaurus Context. Context contains `siteConfig` object from [docusaurus.config.js](docusaurus.config.js.md). | ||
|
||
```ts | ||
interface DocusaurusContext { | ||
siteConfig?: DocusaurusConfig; | ||
} | ||
``` | ||
|
||
Usage example: | ||
|
||
```jsx | ||
import React from 'react'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
|
||
const Test = () => { | ||
const context = useDocusaurusContext(); | ||
const {siteConfig = {}} = context; | ||
const {title} = siteConfig; | ||
|
||
return <h1>{title}</h1>; | ||
}; | ||
``` | ||
|
||
## `useBaseUrl` | ||
|
||
React Hooks to automatically append `baseUrl` to a string automatically. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React hook (singular)
endiliey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example usage: | ||
|
||
```jsx | ||
import React, {useEffect} from 'react'; | ||
import Link from '@docusaurus/Link'; | ||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
|
||
--> | ||
function Help() { | ||
return ( | ||
<div className="col"> | ||
<h2>Browse the docs</h2> | ||
<p> | ||
Learn more about Docusaurus using the{' '} | ||
<Link to={useBaseUrl('docs/introduction')}>official documentation</Link> | ||
endiliey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</p> | ||
</div> | ||
); | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just link people to RR docs instead of replicating the docs.