From 0c09a363a62a9c6d9e5274fcfd8310a6c9728d8e Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Mon, 29 Apr 2024 09:02:47 -0400 Subject: [PATCH] Remove useState hook for the excluded current post that was causing Maximum update depth exceeded errors. --- src/components/post-include-controls.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/components/post-include-controls.js b/src/components/post-include-controls.js index 0f7787a..4db2d7b 100644 --- a/src/components/post-include-controls.js +++ b/src/components/post-include-controls.js @@ -24,8 +24,6 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => { const [ searchArg, setSearchArg ] = useState( '' ); const [ multiplePostsState, setMultiplePostsState ] = useState( multiplePosts ); - const [ excludeCurrentState, setExcludeCurrentState ] = - useState( excludeCurrent ); const posts = useSelect( ( select ) => { @@ -58,8 +56,7 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => { useEffect( () => { if ( JSON.stringify( multiplePosts ) !== - JSON.stringify( multiplePostsState ) || - excludeCurrent !== excludeCurrentState + JSON.stringify( multiplePostsState ) ) { setAttributes( { query: { @@ -68,10 +65,9 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => { }, } ); setMultiplePostsState( multiplePosts ); - setExcludeCurrentState( excludeCurrent ); } - }, [ multiplePosts, excludeCurrent ] ); - + }, [ multiplePosts ] ); + /** * Retrieves the ID of a post based on its title. *