feat(v2): add useBaseUrlUtils() hook (#3033)

* add useBaseUrlUtils

* fix code highlighted lines
This commit is contained in:
Sébastien Lorber 2020-07-08 17:51:59 +02:00 committed by GitHub
parent e5afd1866d
commit a8b2e59a48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 10 deletions

View file

@ -169,7 +169,7 @@ type BaseUrlOptions = {
Example usage:
```jsx {3,11}
import React, {useEffect} from 'react';
import React from 'react';
import Link from '@docusaurus/Link';
import useBaseUrl from '@docusaurus/useBaseUrl';
@ -186,6 +186,24 @@ function Help() {
}
```
### `useBaseUrlUtils`
Sometimes `useBaseUrl` is not good enough. This hook return additional utils related to your site's base url.
- `withBaseUrl`: useful if you need to add base urls to multiple urls at once
```jsx {2,5,6,7}
import React from 'react';
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
function Component() {
const urls = ['/a', '/b'];
const {withBaseUrl} = useBaseUrlUtils();
const urlsWithBaseUrl = urls.map(withBaseUrl);
return <div className="col">{/* ... */}</div>;
}
```
## Modules
### `ExecutionEnvironment`