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

How should I set the arguments and parameters in createAsyncThunk?

$
0
0

Sometimes when I run loadPosts dispatch, I don't send any data, sometimes I send lastId data to same loadPosts disaptch.

At this time, I don't know how to define the type of data in createAsyncThunk .When I run my code I get a red warning in loadPosts.

like this Screenshot

enter image description here

it saysExpected 1 arguments, but got 0.

How can i fix my code?

this is my code

    dispatch(loadPosts());    dispatch(loadPosts(lastId:lastId));    export const loadPosts = createAsyncThunk('post/loadPosts',      async (data: any, thunkAPI) => {        try {          const response = await axios.get(`/post?lastId=${data?.lastId || 0}`);          return response.data;        } catch (error: any) {          return thunkAPI.rejectWithValue(error.response.data);        }      },

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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