I am trying to create a list of inputs using .map and storing the value of the individual inputs in an array. I can add the values to the array, but I can't get the value of the inputs to update from the array.
import React, { Component, useCallback, useState } from "react";
import {
Card,
Subheading,
SkeletonBodyText,
Layout,
Page,
Button,
List,
Heading,
TextField
} from "@shopify/polaris";
export default function Index() {
const [textFieldsList, setTextFieldsList] = useState([null]);
const addTagCall = (value, index) => {
let tester = textFieldsList;
tester[index] = value;
setTextFieldsList(tester);
console.log(value + " index:" + index + " array" + textFieldsList);
};
return (
<Page>
<Heading>Test Page</Heading>
<Layout>
<Layout.Section>
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(i => (
<TextField
label={"Tag" + i}
onChange={newValue => addTagCall(newValue, i)}
value={textFieldsList[i]}
/>
))}
</Layout.Section>
</Layout>
</Page>
);
}