Next.js Discord

Discord Forum

I ran into a problem where filter is not removing the matched item, instead the last element of the

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
array. i tried using both content (which is Date.now()) and index, yet it still removed the last element of the array

const [inputs, setInputs] = useState<number[]>([Date.now()]);


            {inputs.map((input, index) => (
              <div
                key={index}
                id={String(index)}
                className="flex items-end gap-4 space-y-1"
              >
                    onClick={() =>
                      setInputs((prev) =>
                        prev.filter(
                          (innerInput, innerIndex) => innerIndex !== index
              

3 Replies