Skip to content

Instantly share code, notes, and snippets.

@cupofcodeblog
Created February 23, 2024 08:07
Show Gist options
  • Save cupofcodeblog/5646b4f83e923771047f4c6c8cb6a711 to your computer and use it in GitHub Desktop.
Save cupofcodeblog/5646b4f83e923771047f4c6c8cb6a711 to your computer and use it in GitHub Desktop.
Wordle part 3 - post-external json pre-refactoring
function App() {
...
useEffect(()=>{
let randomSolution;
fetch('https://react-wordle-db.netlify.app')
.then(res => res.json())
.then(json => {
// random int between 0 & 14
randomSolution = json.solutions[Math.floor(Math.random()*json.solutions.length)]
setSolution(randomSolution.word)
setSplit(JSON.parse(randomSolution.split));
})
.catch((error) => {
console.log(error);
fetch('http://localhost:3001/solutions')
.then(res => res.json())
.then(json => {
// random int between 0 & 14
randomSolution = json[Math.floor(Math.random()*json.length)]
setSolution(randomSolution.word)
setSplit(JSON.parse(randomSolution.split));
})
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment