Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit 991465d

Browse files
Riley JohnstonRiley Johnston
Riley Johnston
authored and
Riley Johnston
committed
replace use-api-data with axios
1 parent 9106eb1 commit 991465d

File tree

3 files changed

+85
-94
lines changed

3 files changed

+85
-94
lines changed

package-lock.json

Lines changed: 71 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"private": true,
66
"dependencies": {
77
"@carbon/react": "^1.5.0",
8+
"axios": "^0.27.2",
89
"body-parser": "^1.20.0",
910
"concurrently": "^7.2.1",
1011
"cross-env": "^7.0.3",
@@ -17,8 +18,7 @@
1718
"ibm-watson": "^7.0.0",
1819
"lint-staged": "^13.0.1",
1920
"morgan": "^1.10.0",
20-
"sass": "^1.52.3",
21-
"use-data-api": "^1.0.1"
21+
"sass": "^1.52.3"
2222
},
2323
"scripts": {
2424
"dev": "concurrently \"npm:client\" \"npm:server\"",

src/components/ControlContainer/ControlContainer.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TextArea,
1010
Tile,
1111
} from '@carbon/react';
12-
import useDataApi from 'use-data-api';
12+
import axios from 'axios';
1313
import { sampleText } from '../../data/sampleText';
1414
import { mapVoicesToDropdownItems } from './utils';
1515

@@ -19,15 +19,19 @@ export const ControlContainer = ({ onSynthesize }) => {
1919
const [voices, setVoices] = useState([]);
2020
const [selectedVoice, setSelectedVoice] = useState();
2121
const [text, setText] = useState('');
22+
const [isLoading, setIsLoading] = useState(true);
23+
const [isError, setIsError] = useState(false);
2224

23-
const [{ data, isLoading, isError }, doFetch] = useDataApi(VOICES_ENDPOINT, {
24-
voices: [],
25-
});
26-
25+
// Get voices data
2726
useEffect(() => {
28-
doFetch(VOICES_ENDPOINT);
29-
setVoices(data.voices);
30-
}, [data, doFetch, isError, isLoading]);
27+
axios(VOICES_ENDPOINT)
28+
.then(({ data }) => setVoices(data.voices))
29+
.catch(err => {
30+
console.log(err);
31+
setIsError(true);
32+
})
33+
.finally(setIsLoading(false));
34+
}, []);
3135

3236
// Default to initial voice once all voices are loaded.
3337
useEffect(() => {

0 commit comments

Comments
 (0)