Skip to content
This repository was archived by the owner on Jul 7, 2021. It is now read-only.

Commit 97b66b8

Browse files
committed
create createPost action in postAction
1 parent cb7dcb4 commit 97b66b8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/actions/postActions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,20 @@ export const fetchPosts = () => (dispatch) => {
1010
})
1111
);
1212
};
13+
14+
export const createPost = (postData) => (dispatch) => {
15+
fetch("https://jsonplaceholder.typicode.com/posts", {
16+
method: "POST",
17+
headers: {
18+
"content-type": "application/json",
19+
},
20+
body: JSON.stringify(postData),
21+
})
22+
.then((res) => res.json())
23+
.then((post) =>
24+
dispatch({
25+
type: NEW_POST,
26+
payload: post,
27+
})
28+
);
29+
};

0 commit comments

Comments
 (0)