In my React form, I am dealing with an array of objects that represent different fields. Depending on a boolean state, I need to dynamically change the sequence of fields displayed. While I have no trouble inserting a single object into the array, I am struggling to figure out how to insert multiple objects at a specific index.
const [shortForm] = useState(false);
const shortFormFields = {"fieldName":"foo"}
const longFormFields = [
{"fieldName":"bar"},
{"fieldName":"baz"},
{"fieldName":"qux"}]
const finalFieldList = [
{"fieldName":"waldo"},
shortForm === true? shortFormFields : INSERT-BAR-BAZ-QUX-HERE,
{"fieldName":"xyzzy"}]