Skip to content

Instantly share code, notes, and snippets.

@fredbegin11
Last active February 9, 2019 04:19
Show Gist options
  • Select an option

  • Save fredbegin11/ccf4de6b267a3e903e026f24b20911b5 to your computer and use it in GitHub Desktop.

Select an option

Save fredbegin11/ccf4de6b267a3e903e026f24b20911b5 to your computer and use it in GitHub Desktop.
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