@@ -6,39 +6,22 @@ import PropTypes from 'prop-types';
66/**
77 * WordPress dependencies
88 */
9- import {
10- createContext ,
11- useContext ,
12- useEffect ,
13- useRef ,
14- useState ,
15- } from '@wordpress/element' ;
9+ import { createContext , useEffect , useRef , useState } from '@wordpress/element' ;
1610import apiFetch from '@wordpress/api-fetch' ;
17-
18- /**
19- * Internal dependencies
20- */
21- import { ErrorContext } from '../error-context-provider' ;
22- import { useAsyncError } from '../../utils/use-async-error' ;
11+ import { addQueryArgs } from '@wordpress/url' ;
2312
2413export const Plugins = createContext ( ) ;
2514
2615/**
2716 * Plugins context provider.
2817 *
29- * @param {Object } props Component props.
30- * @param {any } props.children Component children.
31- * @param {boolean } props.hasErrorBoundary Whether the component is wrapped in an error boundary.
18+ * @param {Object } props Component props.
19+ * @param {any } props.children Component children.
3220 */
33- export function PluginsContextProvider ( {
34- children,
35- hasErrorBoundary = false ,
36- } ) {
21+ export function PluginsContextProvider ( { children } ) {
3722 const [ plugins , setPlugins ] = useState ( [ ] ) ;
3823 const [ fetchingPlugins , setFetchingPlugins ] = useState ( null ) ;
39-
40- const { error, setError } = useContext ( ErrorContext ) ;
41- const { setAsyncError } = useAsyncError ( ) ;
24+ const [ error , setError ] = useState ( ) ;
4225
4326 /**
4427 * This component sets state inside async functions.
@@ -62,7 +45,9 @@ export function PluginsContextProvider( {
6245
6346 try {
6447 const fetchedPlugins = await apiFetch ( {
65- path : '/wp/v2/plugins' ,
48+ path : addQueryArgs ( '/wp/v2/plugins' , {
49+ _fields : [ 'author' , 'name' , 'plugin' , 'status' , 'version' ] ,
50+ } ) ,
6651 } ) ;
6752
6853 if ( hasUnmounted . current === true ) {
@@ -76,17 +61,11 @@ export function PluginsContextProvider( {
7661 }
7762
7863 setError ( e ) ;
79-
80- if ( hasErrorBoundary ) {
81- setAsyncError ( e ) ;
82- }
83-
84- return ;
8564 }
8665
8766 setFetchingPlugins ( false ) ;
8867 } ) ( ) ;
89- } , [ error , fetchingPlugins , hasErrorBoundary , plugins , setAsyncError , setError ] ) ;
68+ } , [ error , fetchingPlugins , plugins ] ) ;
9069
9170 return (
9271 < Plugins . Provider
@@ -101,5 +80,4 @@ export function PluginsContextProvider( {
10180}
10281PluginsContextProvider . propTypes = {
10382 children : PropTypes . any ,
104- hasErrorBoundary : PropTypes . bool ,
10583} ;
0 commit comments