-
-
Save cupofcodeblog/5646b4f83e923771047f4c6c8cb6a711 to your computer and use it in GitHub Desktop.
Wordle part 3 - post-external json pre-refactoring
This file contains 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
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