update demo-dictionary-app,
This commit is contained in:
21
03_source/mobile/src/pages/DemoDictionaryApp/utils.js
Normal file
21
03_source/mobile/src/pages/DemoDictionaryApp/utils.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { WordStore } from './store';
|
||||
|
||||
const API_URL = 'https://api.dictionaryapi.dev/api/v2/entries/en/';
|
||||
|
||||
export const searchWord = async (word, returnOne = true) => {
|
||||
const response = await fetch(`${API_URL}${word.toLowerCase()}`);
|
||||
const data = await response.json();
|
||||
|
||||
return returnOne ? data[0] : data;
|
||||
};
|
||||
|
||||
export const fetchPopularWords = async () => {
|
||||
const words = ['mobile', 'applications', 'ionic', 'framework'];
|
||||
|
||||
words.forEach(async (word) => {
|
||||
const wordData = await searchWord(word, false);
|
||||
WordStore.update((s) => {
|
||||
s.popularWords = [...s.popularWords, wordData[0]];
|
||||
});
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user