File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ReactQueryDevtools } from 'react-query-devtools'
3
3
import { ReactQueryConfigProvider } from 'react-query'
4
4
5
5
import ReactTable from './components/ReactTable'
6
+ import ReactMutation from './components/ReactMutation'
6
7
7
8
const queryConfig = {
8
9
shared : {
@@ -31,6 +32,7 @@ function App() {
31
32
< div className = 'App' >
32
33
< ReactTable />
33
34
< ReactQueryDevtools />
35
+ < ReactMutation />
34
36
</ div >
35
37
</ ReactQueryConfigProvider >
36
38
)
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { useMutation } from 'react-query'
3
+ import axios from 'axios'
4
+
5
+ const updateAsyncPost = async ( ) => {
6
+ const data = await axios ( 'https://jsonplaceholder.typicode.com/posts' , {
7
+ body : JSON . stringify ( {
8
+ title : 'foo' ,
9
+ body : 'bar' ,
10
+ userId : 1
11
+ } ) ,
12
+ headers : {
13
+ "Content-type" : "application/json; charset=UTF-8"
14
+ }
15
+ } )
16
+ return data
17
+ }
18
+
19
+ const ReactMutation = ( ) => {
20
+
21
+ const [ mutate , info ] = useMutation ( updateAsyncPost )
22
+
23
+ const updatePost = async ( ) => {
24
+ await mutate ( )
25
+ }
26
+
27
+ // eslint-disable-next-line no-undef
28
+ console . log ( { info} )
29
+
30
+ return (
31
+ < div onClick = { updatePost } >
32
+ Click to create a Post - using JSON-PlaceHolder
33
+ </ div >
34
+ )
35
+ }
36
+
37
+ export default ReactMutation
You can’t perform that action at this time.
0 commit comments