The nested createEffect does not trigger again

It seems like I may not have accurately conveyed my issue, but here it is:

When the render signal is triggered, an object creation process occurs that generates additional effects dependent on the update signal. However, the scope appears to be disposed and these effects only fire once at creation time. Despite having references to these objects, how can I ensure that the nested createEffect continues to trigger?

import { render } from 'solid-js/web';
import { on, createSignal, createEffect } from 'solid-js'

function HelloWorld() {

  let [render, setRender] = createSignal(undefined, { equals: false })

  let [update, setUpdate] = createSignal(undefined, { equals: false })
let i = 0

  createEffect(on(render, () => {
    if (i++ === 1) {
      createEffect(on(update, () => {
        console.log('inside')
      }))
    }
  }))

  createEffect(on(update, () => {
    console.log('regular', i)
  }))

 setInterval(() => {
   setUpdate();
    setRender();
  })
  return <div>Hello World!</div>;
}

render(() => <HelloWorld />, document.getElementById('app'))

I am aiming to see both regular and inside logs triggered consistently at each interval.

Answer №1

If you want to update the root of a nested effect using createRoot, you can prevent it from being disposed every time the "parent" effect reruns.

createEffect(() => {
   createRoot(dispose => {
      // Only dispose the effect when
      // dispose() is called
      createEffect(() => {...})
   })
})

Check out this link for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Get the value of the button that has been clicked

I have a query regarding building a website that can be started via PowerShell. The PowerShell HTML code I am using is: $proxys = "" foreach ($email in $ADObj.proxyAddresses){ $proxys += "<button id='$email' name='alias&apo ...

SVG.js created a surprising polyline in the svgdom node

My svg.js code generates different SVG strings in the browser (correct) and at node (incorrect with excessive inner SVG elements). Here is my code for the browser: let size = { width: 512, height: 512 }; let entity = { x: 232, y: 162, rx: 137, r ...

What steps can be taken to provide accurate information in the absence of ImageData?

Utilizing a JS library to convert a raster image into a vector, I encountered an issue where the library returned a fill of solid color instead of the desired outcome. I suspect that the problem lies within the ArrayBuffer. The process of loading an imag ...

Using TypeORM in Javascript to create routes efficiently

After examining the TypeORM websites examples, I noticed that some of them demonstrate routing usage using TypeScript. Given that TypeORM has the capability to use JavaScript instead of TypeScript, I am seeking guidance on how to implement Express routing ...

The ng-blur functionality will only trigger if the click event occurs within the bounds of the textbox

I am facing an issue with a textbox that should display a certain value even after being deleted. When the input is cleared and clicked away from, I want the value to reappear in the textbox. Currently, there seems to be a problem with this functionality ...

Ensure that only the most recent Ajax request is allowed

In my project, I have an input box that triggers an ajax request with every key press. This means if I type the word "name," there will be a total of 4 requests sent out. However, what I really need is to only execute the latest request. So even if I enter ...

Move to the following <article>

I am currently working on developing a JavaScript function that will automatically scroll to the next article whenever the down arrow key is pressed. The challenge I am facing is that my HTML elements are all dynamic and are simply article tags without any ...

Can a strict type be created from a partial type?

By utilizing TypeScript 2.1, we have the ability to generate a partial type from a strict type as demonstrated below: type Partial<T> = { [P in keyof T]?: T[P]; }; type Person = { name: string, age: number } type PersonPartial = Partial<Pers ...

Since transitioning my project from Angular 7.2 to Angular 8, I noticed a significant threefold increase in compile time. How can I go about resolving this issue

After upgrading my project to Angular 8, I noticed a significant increase in compile time without encountering any errors during the upgrade process. Is there a way to restore the previous compile time efficiency? **Update: A bug has been identified as th ...

Error Encountered During JavaScript Form Validation

Currently, I am troubleshooting a website that was created by another developer. There is a form with JavaScript validation to ensure data is accurately entered into the database. However, I am puzzled as to why I keep receiving these alert messages. Pleas ...

Transmitting solely the updated information from the database

I am working on a table that is populated with data from the server using ajax. The table has columns A, B, C, and D where C and D are editable by the user. After the user makes changes to the data in the table, I need to capture only the lines that have b ...

What is the best way to save a current HTML element for later use?

Here is a simple HTML code that I would like to save the entire div with the class test_area and then replicate it when needed. Currently, my goal is to duplicate this div and place the clone underneath the original element. How can I achieve this? Unfortu ...

The jQuery scripts are having trouble cooperating

Currently, I am in the process of developing a website. The main focus at the moment is on creating a responsive menu and incorporating jQuery scripts. However, I seem to be facing some challenges in getting everything to work seamlessly together. Each scr ...

Encountering a 500 internal server error when utilizing jQuery and Ajax with Laravel 5.2

I have been working on a post editing system using jQuery and Ajax in Laravel 5.2. But when I try to save the changes by clicking on the button inside my Bootstrap modal, an error pops up: Error: POST http://localhost:8000/edit 500 (Internal Server Error) ...

The dynamically generated table will only show the most recently added data

Currently, I am delving into the world of JavaScript to tackle an interesting challenge. Here's the scenario: I have a dropdown list populated with stream names derived from an array. Whenever a selection in this array changes using `onchange()`, I wa ...

What is the best way to set values for the outcomes of a jQuery/AJAX post?

When sending data to a php page using jquery, I aim to receive the response from the page and store it in php variables on the original page without displaying results in the HTML or appending a DIV. Here's an example of how this can be achieved: Sam ...

Enhancing Functional Components with Idle Timeout using React Hooks

I am currently working on an application that requires implementing an idle timeout feature. This feature should first notify the user that they will be logged out in one minute, and then proceed to log them out after the time has expired. Previously, I s ...

Is there a way to apply Validators.required just once for all required form fields in a Reactive Form?

Latest version of Angular is 4.4.3. In Reactive Form, you can use Validators.required for each form field as shown below: this.loginForm = this.fb.group({ firstName: ['', [Validators.required, Validators.maxLength(55)]], ...

Refusing to handle HTTP requests in Node and Express API for MongoDB interactions

I am currently in the process of creating a basic API for performing CRUD operations on a local mongo database. Despite having what seems like correct code, the CRUD operations result in pending requests that never seem to complete. Below are snippets of ...

vue-router default route for children

Currently, I am working on a Vue 2.x application and utilizing vue-router for routing purposes. In certain situations, I need to directly display a child vue. The template structure is as follows: | voice 1 | voice 2 | voice 3 | | submenu 1 | submen ...