Gathering detailed insights and metrics for @micyo/react-wp-query
Gathering detailed insights and metrics for @micyo/react-wp-query
Gathering detailed insights and metrics for @micyo/react-wp-query
Gathering detailed insights and metrics for @micyo/react-wp-query
npm install @micyo/react-wp-query
Typescript
Module System
Node Version
NPM Version
69.2
Supply Chain
95.6
Quality
85.7
Maintenance
50
Vulnerability
95.8
License
TypeScript (76.35%)
JavaScript (13.02%)
CSS (6.75%)
MDX (3.87%)
Total Downloads
783
Last Day
6
Last Week
25
Last Month
272
Last Year
783
MIT License
3 Stars
78 Commits
1 Forks
2 Watchers
2 Branches
1 Contributors
Updated on May 06, 2025
Minified
Minified + Gzipped
Latest Version
2.1.3
Package Id
@micyo/react-wp-query@2.1.3
Unpacked Size
266.25 kB
Size
52.69 kB
File Count
15
NPM Version
10.8.1
Node Version
20.14.0
Published on
May 05, 2025
Cumulative downloads
Total Downloads
Last Day
500%
6
Compared to previous day
Last Week
8.7%
25
Compared to previous week
Last Month
1,600%
272
Compared to previous month
Last Year
0%
783
Compared to previous year
3
With the @micyo/react-wp-query library, you can develop web pages and applications within a few hours using the WordPress REST API. Thanks to the existing hooks and helper components in the library, you can easily make your customizations. All that’s left for you is to apply styling to your web page.
The package can be installed via npm
1npm install @micyo/react-wp-query --save
or via yarn
1yarn add @micyo/react-wp-query
Wrap your project with the WPProvider component and pass the WordPress REST API URL you want to connect to as the api prop to the component. With the clickEvent prop, you can handle virtual routing for post meta clicks. You can adjust the date format for all date components on the pages using the formatDate prop. The links are set up in this way to allow you to work with any react framework or library you prefer.
1import { useCallback } from 'react'; 2import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; 3import { WPProvider } from '@micyo/react-wp-query'; 4 5const queryClient = new QueryClient(); 6 7const App = ({ children }) => { 8 const clickEvent = useCallback(({ event, values, type }) => { 9 event.preventDefault(); 10 // 11 if (type === 'author') { 12 // redirect author page with **values** arguments 13 } 14 }, []); 15 16 const formatDate = useCallback((date) => { 17 // format your date here 18 return date; 19 }, []); 20 21 return ( 22 <WPProvider 23 api="https://wordpress.org/news/wp-json/" 24 clickEvent={clickEvent} 25 formatDate={formatDate}> 26 <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> 27 </WPProvider> 28 ); 29}; 30 31export default App;
The example below uses a custom fetch handler for making all the requests with axios.
1import apiFetch from '@wordpress/api-fetch'; 2import axios from 'axios'; 3 4apiFetch.setFetchHandler((options) => { 5 const { url, path, data, method } = options; 6 7 return axios({ 8 url: url || path, 9 method, 10 data 11 }); 12});
## Hooks
Get posts with usePosts Hook
1import { usePosts, Post, Title, Meta, Excerpt } from '@micyo/react-wp-query'; 2 3const LatestNews = () => { 4 const [page, setPage] = React.useState(1); 5 const { posts, pagination } = usePosts({ 6 queryArgs: { 7 page 8 } 9 }); 10 11 return posts?.isLoading ? ( 12 <>Loading...</> 13 ) : ( 14 <> 15 {Array.isArray(posts?.data) && 16 posts?.data?.map((post) => ( 17 <Post key={`posts-${post.id}`} post={post}> 18 <Title /> 19 <Meta /> 20 <Excerpt /> 21 </Post> 22 ))} 23 24 <button onClick={() => setPage((p) => p - 1)} disabled={!pagination.hasPrev}> 25 Prev Page 26 </button> 27 <button onClick={() => setPage((p) => p + 1)} disabled={!pagination.hasNext}> 28 Next Page 29 </button> 30 </> 31 ); 32}; 33 34export default LatestNews;
Copyright (c) 2024 themesama and individual contributors. Licensed under MIT license, see LICENSE for the full license.
No vulnerabilities found.
No security vulnerabilities found.