# useEffect, useLayoutEffect and useInsertionEffect

## Syntax

```javascript
useEffect(effectCallback, optionalArgumentList);
```

Where :

1. `effectCallback` : Function that is executed one or more times according to `optionalArgumentList`,`effectCallback` can return a function that will be executed only if `effectCallback` is executed again or the webcomponent is unmounted.
2. `optionalArgumentList`: Array of arguments that controls the execution of `effectCallback`, if an argument of`optionalArgumentList` changes it will trigger that `effectCallback` is executed again without first cleaning the effects subscribed by the previous execution.

## Example

```javascript
const listenerClickWindow = () => {
  const handlerClick = () => {
    console.log("Click window!");
  };

  window.addEventListener("click", handlerClick);

  const unlistenerClickWindow = () =>
    window.removeEventListener("click", handlerClick);

  return unlistenerClickWindow;
};

useEffect(listenerClickWindow, []);
```

## useLayoutEffect

useLayoutEffect replicates the logic of useEffect but with synchronous execution after rendering.

## useInsertionEffect

useLayoutEffect replicates the logic of useEffect but with synchronous execution before rendering.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://atomico.gitbook.io/doc/api/hooks/useeffect-y-uselayouteffect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
