Here is the state:
const [state, setState] = useState({
menuCatalog: true,
menuCommon: true,
fetched_data: []
});
This is an example of fetched data I try to set to the state property "fetched_data":
[{"id": 1, "name": "some_name", "ip": "127.0.0.1", "port": 5353}, {"id": 2, "name": "some_name", "ip": "128.0.0.1", "port": 5353}]
This is how I try to set it:
const fetched_stuff = await fetchStuff();
const fetched_data = fetched_stuff["data"];
setState({
fetched_data
});
And this is error I get:
Argument of type '{ fetched_data: any; }' is not assignable to parameter of type 'SetStateAction<{ menuCatalog: boolean; menuCommon: boolean; fetched_data: never[]; }>'.
Type '{ fetched_data: any; }' is missing the following properties from type '{ menuCatalog: boolean; menuCommon: boolean; fetched_data: never[]; }': menuCatalog, menuCommon TS2345
Tried a dozen different things, no solutions online help. How to actually set the array of objects to the state in typescript.react?
setState({menuCatalog: true,menuCommon: true,fetched_data});?setState(prev => ({...prev, fetched_data})). It's possible that the booleans may not always be true.