#force a dom update when updating a signal before the rest of the onMount function

9 messages · Page 1 of 1 (latest)

distant kelp
#

in this code csvColumns is dependant on setData, how can I force the render update?


  const csvColumns = (
    <Show when={data()}>
      <For each={data()}>{(item, index) => <ConnectionTarget name={item} />}</For>
    </Show>
  );

  onMount(() => {
    const csv = `Name,Email,Age
John Doe,[email protected],30
Jane Smith,[email protected],25
Alice Johnson,[email protected],35
`;
    const rows = csv.split('\n');
    const firstRow = rows[0].split(',');
    setData(firstRow);

    //offload the line drawing
    debugger;
    const colsX = csvColumns.map((component) => component());
  });```
upbeat schooner
#

the golden rule is that memos and effects are re-executed and ~nothing else

#

so if you want something to re-execute when some signal changes make sure to wrap the code in a memo or an effect, and read the signal inside that

#

so in this case you should probably make csvColumns a memo

#

Although setData sounds like the setter for a signal, signal presumably called data, signal called data that presumably you are already depending on. So shouldn't this just work? Maybe the value passed to setData is just the old value for data, but mutated (which is not detected as a change)?

distant kelp
#

why do need blackbox terms like memo? ><

upbeat schooner
#

memo as in createMemo, one of the main functions in Solid

distant kelp
#

ill just use effect, easier to understand