Skip to content

Commit

Permalink
Merge pull request #53 from ryanwelcher/fix/exclude-current-error
Browse files Browse the repository at this point in the history
Remove useState hook for the excluded current post that was causing Maximum update depth exceeded errors.
  • Loading branch information
ryanwelcher authored Apr 29, 2024
2 parents fe71cd9 + 0c09a36 commit bc4104d
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 bc4104d

Please sign in to comment.