Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useEffect #68370

Closed
Pixelous opened this issue Dec 29, 2024 · 0 comments
Closed

useEffect #68370

Pixelous opened this issue Dec 29, 2024 · 0 comments
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@Pixelous
Copy link

Pixelous commented Dec 29, 2024

Hi,

Can anyone please point me in a right direction how useEffect hook works?

The code is:

// Masonry
	const ref = useRef();

	const blockProps = useBlockProps( {
		className: clsx( className, 'has-nested-images' ),
		ref: ref,
	} );

useEffect( () => {
		if ( ! ref.current ) {
			return;
		}
		console.log( ref.current );
		return () => {
			console.log( 'deleted' );
		}
	}, [] );

After page updating is what I am seeing in a console:

ref.current
deleted
ref.current

Why 'deleted' is adding to the console if 'ref.current' exists?

Page-No-Title-.-Template-.-wordpress-local-.-Editor-.-WordPress.webm

Kind regards

@stokesman stokesman added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Dec 29, 2024
@WordPress WordPress locked and limited conversation to collaborators Dec 29, 2024
@stokesman stokesman converted this issue into discussion #68371 Dec 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

2 participants