Skip to content

Commit

Permalink
Remove useState hook for the excluded current post that was causing M…
Browse files Browse the repository at this point in the history
…aximum update depth exceeded errors.
  • Loading branch information
ryanwelcher committed Apr 29, 2024
1 parent fe71cd9 commit 0c09a36
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/components/post-include-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand Down Expand Up @@ -58,8 +56,7 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => {
useEffect( () => {
if (
JSON.stringify( multiplePosts ) !==
JSON.stringify( multiplePostsState ) ||
excludeCurrent !== excludeCurrentState
JSON.stringify( multiplePostsState )
) {
setAttributes( {
query: {
Expand All @@ -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.
*
Expand Down

0 comments on commit 0c09a36

Please sign in to comment.