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

How do I set up typescript in Redux toolkit?

$
0
0

I want to receive data from redux toolkit's createAsyncThunk when dispatching.

But I don't know how to set the data type.

If no data type is specified, a warning line is displayed with a red line.

like this Screenshot

enter image description here

How do I specify the type?

this is my code

    // commentinput is string and post.id is number    const commetsubmitfun = useCallback(() => {      dispatch(addComment({content: commentinput, postId: post.id}));    }, [dispatch, commentinput]);    export const addComment = createAsyncThunk('post/addComment',      async (data, {rejectWithValue}) => {        try {          //    data: {content: "aaa", postId: 66}          const response = await axios.post(`/post/${data.postId}/comment`, data); // POST /post/1/comment          return response.data;        } catch (error: any) {          return 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>