1
1
import React , { useState , useEffect , useCallback } from "react" ;
2
2
import debounce from 'lodash.debounce' ;
3
+ import axios from 'axios' ;
3
4
4
5
/*
5
6
* @author Blake Vente
@@ -9,11 +10,12 @@ import debounce from 'lodash.debounce';
9
10
const ENDPOINT = process . env . GATSBY_PANDOC_ENDPOINT ;
10
11
const MARKUP = "# edit me! \n## numbered list example \n1. first item\n2. second item" ;
11
12
12
-
13
+ // styles
13
14
const darkBackground = {
14
15
color : "rgb(214, 222, 235)" ,
15
16
backgroundColor : "rgb(1, 22, 39)" ,
16
17
} ;
18
+
17
19
const inputField = {
18
20
width : "100%" ,
19
21
height : "400px" ,
@@ -29,24 +31,21 @@ const breakStyle = {
29
31
} ;
30
32
31
33
export default function Convert ( ) {
32
- var myHeaders = new Headers ( ) ;
33
- myHeaders . append ( "Content-Type" , "application/json" ) ;
34
-
35
34
const [ convertReponse , setConvertResponse ] = useState ( "" ) ;
36
35
const [ markupRequest , setMarkupRequest ] = useState ( MARKUP ) ;
37
36
37
+
38
38
const HitConvertEndpoint = async ( r ) => {
39
- const requestOptions = {
40
- method : 'POST' ,
41
- headers : myHeaders ,
42
- body : JSON . stringify ( { "markup" : r } ) ,
43
- redirect : 'follow'
44
- } ;
45
- const res = await fetch ( ENDPOINT , requestOptions )
46
- . then ( response => response . text ( ) )
39
+ const res = await axios . post ( ENDPOINT , { "markup" : r } , {
40
+ headers : {
41
+ "Content-Type" : "application/json"
42
+ }
43
+ } )
44
+ . then ( response => response ?. data )
45
+ . then ( response => { console . log ( response ) ; return response } )
47
46
. catch ( error => console . log ( 'error' , error ) ) ;
48
47
49
- setConvertResponse ( JSON . parse ( res ) ? .result ) ;
48
+ setConvertResponse ( res . result ) ;
50
49
} ;
51
50
52
51
const handleInputChange = ( e ) => {
0 commit comments