SolidJSS
SolidJSโ€ข10mo agoโ€ข
5 replies
Lalakis Alfa Ordner

Update array of signal by index, it does unfocus on typing

When i type a letter on the input it loses focus trying to update and arr based on index.

<For each={names()}>
        {(name, index) => (
          <div class={styles.inputGroup}>
            <input
              type="text"
              value={name}
              onInput={(e) => updateName(index(), e.target.value)}
              placeholder="Enter name"
              class={styles.input}
            />
          </div>
        )}
      </For>
      

 const [names, setNames] = createSignal([''], { equals: false });

  const addName = () => {
    setNames([...names(), '']);
  };

  const updateName = (index: number, value: string) => {
    setNames((prev) => {
      const newNames = [...prev];
      newNames[index] = value;
      return newNames;
    });
  };
Was this page helpful?