Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Argument of type 'void' is not assignable to parameter of type 'SetStateAction'

$
0
0

I am getting the following error:

Argument of type 'void' is not assignable to parameter of type 'SetStateAction<never[]>'.

My relevant code looks like this:

const ViewEvents: React.FC<ViewEventsProps> = ({ navigation }) => {const flatListRef = useRef(null);const [limit] = useState(5);const [page, setPage] = useState(1);const [clientData, setClientData] = useState([]);const [serverData, serverDataLoaded] = useState([]);const [pending_process, setPending_process] = useState(true);const [loadmore, setLoadmore] = useState(false);const [refresh, setRefresh] = useState(false);const getEvents = async (thePage: any) => {    try {        const value = await AsyncStorage.getItem('user_id');        if (value !== null) {            // We have data!!            const user_id = JSON.parse(value)            const response = await APIKit.get('/v1/events/user-events/'+ user_id)                .then((response) => {                    console.log(response.data)                    return response.data.slice((thePage - 1) * limit, thePage * limit);                }, (error) => {                    console.log(error);                });        }    } catch (error) {        // Error retrieving data    }}const requestToServer = async (thePage: any) => {    let data = await getEvents(thePage);    console.log('data', data);    serverDataLoaded(data);};

Obviously data is not being initialized with the data returned from the getEvents function. What I cannot figure out is why? I am using TypeScript and so far no errors are being thrown from the getEvents function.

I am new to React and TypeScript so I might be missing something and so far all the similar questions I have seen online do not seem to be relevant to my error.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>