Last active
February 9, 2019 04:19
-
-
Save fredbegin11/ccf4de6b267a3e903e026f24b20911b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios from 'axios'; | |
| import React, { useState, useEffect } from 'react'; | |
| const Rhyme = () => { | |
| const [word, setWord] = useState(''); | |
| const [rhymes, setRhymes] = useState([]); | |
| const fetchRhyme = async () => { | |
| const response = await axios.get(`https://api.datamuse.com/words?rel_rhy=${word}`); | |
| setRhymes(response.data); | |
| }; | |
| useEffect(() => { | |
| fetchRhyme(); | |
| }, [word]); | |
| return ( | |
| <> | |
| <input value={word} onChange={event => setWord(event.currentTarget.value)} /> | |
| <div> | |
| <h3>Rhymes</h3> | |
| {rhymes.map(rhyme => ( | |
| <p key={rhyme.word}>{rhyme.word}</p> | |
| ))} | |
| </div> | |
| </> | |
| ); | |
| }; | |
| export default Rhyme; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment