Skip to content

Commit 2115b85

Browse files
authored
3.1.0 (#98)
* feat: add useWordPress hook * refactor: clean up * chore: update * docs: update example * docs: update urls * docs: update example * docs: update example * docs: update example * chore: v3.1.0
1 parent f59620e commit 2115b85

File tree

9 files changed

+90
-40
lines changed

9 files changed

+90
-40
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# react-wordpress-hooks Changelog
22

3+
## 3.1.0 (2020-06-01)
4+
5+
#### New Feature
6+
7+
- added `useWordPress` hook
8+
39
## 3.0.2 (2020-04-19)
410

511
#### Repository Changes

docs/block-revisions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ menu: Hooks
88

99
### useRetrieveBlockRevisions
1010

11-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_block-revisions/#retrieve-a-wp_block-revision)
11+
[Available options](https://developer.wordpress.org/rest-api/reference/block-revisions/#retrieve-a-wp_block-revision)
1212

1313
```jsx
1414
const { data, loading, error } = useRetrieveBlockRevisions(
@@ -19,7 +19,7 @@ const { data, loading, error } = useRetrieveBlockRevisions(
1919

2020
### useCreateBlockRevisions
2121

22-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_block-revisions/#create-a-wp_block-revision)
22+
[Available options](https://developer.wordpress.org/rest-api/reference/block-revisions/#create-a-wp_block-revision)
2323

2424
```jsx
2525
const { data, loading, error } = useCreateBlockRevisions(
@@ -30,7 +30,7 @@ const { data, loading, error } = useCreateBlockRevisions(
3030

3131
### useRetrieveBlockRevision
3232

33-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_block-revisions/#retrieve-a-wp_block-revision-2)
33+
[Available options](https://developer.wordpress.org/rest-api/reference/block-revisions/#retrieve-a-wp_block-revision-2)
3434

3535
```jsx
3636
const { data, loading, error } = useRetrieveBlockRevision(

docs/blocks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ menu: Hooks
77

88
### useBlocks
99

10-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_blocks/#list-wp_blocks)
10+
[Available options](https://developer.wordpress.org/rest-api/reference/blocks/#list-wp_blocks)
1111

1212
Default query (latest 10 blocks):
1313

@@ -37,7 +37,7 @@ const { data, loading, error } = useComments(/* array of block ids */);
3737

3838
### useCreateBlock
3939

40-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_blocks/#create-a-wp_block)
40+
[Available options](https://developer.wordpress.org/rest-api/reference/blocks/#create-a-wp_block)
4141

4242
```jsx
4343
const { data, loading, error } = useCreateBlock({
@@ -47,7 +47,7 @@ const { data, loading, error } = useCreateBlock({
4747

4848
### useRetrieveBlock
4949

50-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_blocks/#retrieve-a-wp_block)
50+
[Available options](https://developer.wordpress.org/rest-api/reference/blocks/#retrieve-a-wp_block)
5151

5252
```jsx
5353
const { data, loading, error } = useRetrieveBlock({
@@ -57,7 +57,7 @@ const { data, loading, error } = useRetrieveBlock({
5757

5858
### useUpdateBlock
5959

60-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_blocks/#update-a-wp_block)
60+
[Available options](https://developer.wordpress.org/rest-api/reference/blocks/#update-a-wp_block)
6161

6262
```jsx
6363
const { data, loading, error } = useUpdateBlock({
@@ -67,7 +67,7 @@ const { data, loading, error } = useUpdateBlock({
6767

6868
### useDeleteBlock
6969

70-
[Available options](https://developer.wordpress.org/rest-api/reference/wp_blocks/#delete-a-wp_block)
70+
[Available options](https://developer.wordpress.org/rest-api/reference/blocks/#delete-a-wp_block)
7171

7272
```jsx
7373
const { data, loading, error } = useDeleteBlock(

docs/wordpress.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
route: /hooks/wordpress
3+
menu: Hooks
4+
---
5+
6+
## Custom Endpoints
7+
8+
### useWordPress
9+
10+
This hook allows you to use custom endpoints or create manual requests to WordPress REST API
11+
12+
[Read more about custom enpoints](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/)
13+
14+
```jsx
15+
const { data, loading, error } = useWordPress({
16+
// endpoint (e.g.: slides)
17+
// options (request option params)
18+
// requsetMethod: (e.g.: GET, POST)
19+
});
20+
```

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-wordpress-hooks",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"description": "Set of hooks for WordPress REST API",
55
"author": "Jakub Biesiada",
66
"license": "MIT",
@@ -36,16 +36,16 @@
3636
"devDependencies": {
3737
"@rollup/plugin-node-resolve": "^8.0.0",
3838
"@types/react": "^16.9.35",
39-
"@typescript-eslint/parser": "^3.0.0",
39+
"@typescript-eslint/parser": "^3.1.0",
4040
"docz": "^2.3.1",
4141
"eslint": "^7.1.0",
4242
"eslint-config-prettier": "^6.11.0",
4343
"eslint-plugin-prettier": "^3.1.3",
4444
"eslint-plugin-react": "^7.20.0",
45-
"eslint-plugin-react-hooks": "^4.0.2",
46-
"gh-pages": "^2.2.0",
45+
"eslint-plugin-react-hooks": "^4.0.4",
46+
"gh-pages": "^3.0.0",
4747
"husky": "^4.2.5",
48-
"lint-staged": "^10.2.6",
48+
"lint-staged": "^10.2.7",
4949
"prettier": "^2.0.5",
5050
"react": "^16.13.1",
5151
"react-dom": "^16.13.1",

src/hooks/useApiRequest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const useApiRequest = ({
7979
}
8080
} catch (err) {
8181
setLoading(false);
82+
8283
setError(err);
8384
}
8485
}

src/hooks/useWordPress.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useApiRequest } from './useApiRequest';
2+
3+
type UseWordPress = {
4+
readonly endpoint: string;
5+
readonly options?: number | object;
6+
readonly requsetMethod?: string;
7+
};
8+
9+
export const useWordPress = ({
10+
endpoint,
11+
options,
12+
requsetMethod,
13+
}: UseWordPress) => {
14+
const { data, loading, error } = useApiRequest({
15+
endpoint,
16+
options,
17+
requsetMethod,
18+
});
19+
20+
return { data, loading, error };
21+
};

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ export * from './hooks/useSettings';
1717
export * from './hooks/useThemes';
1818
export * from './hooks/useSearch';
1919

20+
export * from './hooks/useWordPress';
21+
2022
export { WordPressProvider } from './context';

yarn.lock

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,13 +1483,13 @@
14831483
eslint-scope "^5.0.0"
14841484
eslint-utils "^2.0.0"
14851485

1486-
"@typescript-eslint/experimental-utils@3.0.0":
1487-
version "3.0.0"
1488-
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.0.0.tgz#1ddf53eeb61ac8eaa9a77072722790ac4f641c03"
1489-
integrity sha512-BN0vmr9N79M9s2ctITtChRuP1+Dls0x/wlg0RXW1yQ7WJKPurg6X3Xirv61J2sjPif4F8SLsFMs5Nzte0WYoTQ==
1486+
"@typescript-eslint/experimental-utils@3.1.0":
1487+
version "3.1.0"
1488+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.1.0.tgz#2d5dba7c2ac2a3da3bfa3f461ff64de38587a872"
1489+
integrity sha512-Zf8JVC2K1svqPIk1CB/ehCiWPaERJBBokbMfNTNRczCbQSlQXaXtO/7OfYz9wZaecNvdSvVADt6/XQuIxhC79w==
14901490
dependencies:
14911491
"@types/json-schema" "^7.0.3"
1492-
"@typescript-eslint/typescript-estree" "3.0.0"
1492+
"@typescript-eslint/typescript-estree" "3.1.0"
14931493
eslint-scope "^5.0.0"
14941494
eslint-utils "^2.0.0"
14951495

@@ -1503,14 +1503,14 @@
15031503
"@typescript-eslint/typescript-estree" "2.27.0"
15041504
eslint-visitor-keys "^1.1.0"
15051505

1506-
"@typescript-eslint/parser@^3.0.0":
1507-
version "3.0.0"
1508-
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.0.0.tgz#fe9fdf18a1155c02c04220c14506a320cb6c6944"
1509-
integrity sha512-8RRCA9KLxoFNO0mQlrLZA0reGPd/MsobxZS/yPFj+0/XgMdS8+mO8mF3BDj2ZYQj03rkayhSJtF1HAohQ3iylw==
1506+
"@typescript-eslint/parser@^3.1.0":
1507+
version "3.1.0"
1508+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.1.0.tgz#9c02ba5d88ad2355672f39e6cd4176f172dd47f8"
1509+
integrity sha512-NcDSJK8qTA2tPfyGiPes9HtVKLbksmuYjlgGAUs7Ld2K0swdWibnCq9IJx9kJN8JJdgUJSorFiGaPHBgH81F/Q==
15101510
dependencies:
15111511
"@types/eslint-visitor-keys" "^1.0.0"
1512-
"@typescript-eslint/experimental-utils" "3.0.0"
1513-
"@typescript-eslint/typescript-estree" "3.0.0"
1512+
"@typescript-eslint/experimental-utils" "3.1.0"
1513+
"@typescript-eslint/typescript-estree" "3.1.0"
15141514
eslint-visitor-keys "^1.1.0"
15151515

15161516
"@typescript-eslint/[email protected]":
@@ -1526,10 +1526,10 @@
15261526
semver "^6.3.0"
15271527
tsutils "^3.17.1"
15281528

1529-
"@typescript-eslint/typescript-estree@3.0.0":
1530-
version "3.0.0"
1531-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.0.0.tgz#fa40e1b76ccff880130be054d9c398e96004bf42"
1532-
integrity sha512-nevQvHyNghsfLrrByzVIH4ZG3NROgJ8LZlfh3ddwPPH4CH7W4GAiSx5qu+xHuX5pWsq6q/eqMc1io840ZhAnUg==
1529+
"@typescript-eslint/typescript-estree@3.1.0":
1530+
version "3.1.0"
1531+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.1.0.tgz#eaff52d31e615e05b894f8b9d2c3d8af152a5dd2"
1532+
integrity sha512-+4nfYauqeQvK55PgFrmBWFVYb6IskLyOosYEmhH3mSVhfBp9AIJnjExdgDmKWoOBHRcPM8Ihfm2BFpZf0euUZQ==
15331533
dependencies:
15341534
debug "^4.1.1"
15351535
eslint-visitor-keys "^1.1.0"
@@ -4788,10 +4788,10 @@ eslint-plugin-react-hooks@^1.7.0:
47884788
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-1.7.0.tgz#6210b6d5a37205f0b92858f895a4e827020a7d04"
47894789
integrity sha512-iXTCFcOmlWvw4+TOE8CLWj6yX1GwzT0Y6cUfHHZqWnSk144VmVIRcVGtUAzrLES7C798lmvnt02C7rxaOX1HNA==
47904790

4791-
eslint-plugin-react-hooks@^4.0.2:
4792-
version "4.0.2"
4793-
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.0.2.tgz#03700ca761eacc1b6436074c456f90a8e331ff28"
4794-
integrity sha512-kAMRjNztrLW1rK+81X1NwMB2LqG+nc7Q8AibnG8/VyWhQK8SP6JotCFG+HL4u1EjziplxVz4jARdR8gGk8pLDA==
4791+
eslint-plugin-react-hooks@^4.0.4:
4792+
version "4.0.4"
4793+
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.0.4.tgz#aed33b4254a41b045818cacb047b81e6df27fa58"
4794+
integrity sha512-equAdEIsUETLFNCmmCkiCGq6rkSK5MoJhXFPFYeUebcjKgBmWWcgVOqZyQC8Bv1BwVCnTq9tBxgJFgAJTWoJtA==
47954795

47964796
eslint-plugin-react@^7.19.0:
47974797
version "7.19.0"
@@ -6194,10 +6194,10 @@ getpass@^0.1.1:
61946194
dependencies:
61956195
assert-plus "^1.0.0"
61966196

6197-
gh-pages@^2.2.0:
6198-
version "2.2.0"
6199-
resolved "https://registry.yarnpkg.com/gh-pages/-/gh-pages-2.2.0.tgz#74ebeaca8d2b9a11279dcbd4a39ddfff3e6caa24"
6200-
integrity sha512-c+yPkNOPMFGNisYg9r4qvsMIjVYikJv7ImFOhPIVPt0+AcRUamZ7zkGRLHz7FKB0xrlZ+ddSOJsZv9XAFVXLmA==
6197+
gh-pages@^3.0.0:
6198+
version "3.0.0"
6199+
resolved "https://registry.yarnpkg.com/gh-pages/-/gh-pages-3.0.0.tgz#65f3ccd424bfbc7906f31c4bdb524a1147fa8da2"
6200+
integrity sha512-oaOfVcrSwnqoWUgZ6cmCDM6mUuWyOSG+SHjqxGBawN0F3SKaF5NwbeYDG+w2RNXO2HJ/5Iam4o7dP5NAtoHuwQ==
62016201
dependencies:
62026202
async "^2.6.1"
62036203
commander "^2.18.0"
@@ -8020,10 +8020,10 @@ lines-and-columns@^1.1.6:
80208020
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
80218021
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=
80228022

8023-
lint-staged@^10.2.6:
8024-
version "10.2.6"
8025-
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.2.6.tgz#7d9658bd89dee946a859cbfc6e09566a9fb50b53"
8026-
integrity sha512-2oEBWyPZHkdyjKcIv2U6ay80Q52ZMlZZrUnfsV0WTVcgzPlt3o2t5UFy2v8ETUTsIDZ0xSJVnffWCgD3LF6xTQ==
8023+
lint-staged@^10.2.7:
8024+
version "10.2.7"
8025+
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.2.7.tgz#6e47860af3d86a6a01849cbf8ba80f7754aae6eb"
8026+
integrity sha512-srod2bTpF8riaLz+Bgr6v0mI/nSntE8M9jbh4WwAhoosx0G7RKEUIG7mI5Nu5SMbTF9o8GROPgK0Lhf5cDnUUw==
80278027
dependencies:
80288028
chalk "^4.0.0"
80298029
cli-truncate "2.1.0"

0 commit comments

Comments
 (0)