I'm trying to save an array to state and then I want to somehow loop over the array that was saved to state in the dom to create an unordered list using one item from the array for each
import React, { useState } from 'react';
const Worbli: React.FC = () => {
const [state, setState] = useState({
myArray = '';
});
const theArrayToSave = ['apple', 'orange', 'peach']
setState({ ...state, myArray: theArrayToSave });
return (
<ul>
{ state.myArray.map( (fruit:string,index:number) => (<li key={index} >{fruit}</li>)) }
</ul>
)
}
The error I get is
Argument of type '{ myArray: string[]; accountNameError: string; loading: boolean; }' is not assignable to parameter of type 'SetStateAction<{ accountNameError: string; loading: boolean; myArray: string; }>'.
Type '{ myArray: string[]; }' is not assignable to type '{ myArray: string; }'.
Types of property 'myArray' are incompatible.
Type 'string[]' is not assignable to type 'string'.ts(2345)
myArray = [];