Created
August 24, 2021 04:39
-
-
Save cvega21/a6721eb351d9bf7dce2eaa28fa7e88ba to your computer and use it in GitHub Desktop.
Keep portfolio data as app-level state
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() { | |
const [projectsData, setProjectsData] = useState({projects: {placeholder: ''}, projectsMetadata: {placeholder: ''}}); | |
... | |
useEffect(() => { | |
const getProjects = async () => { | |
let firebaseReq = await database.ref(`/`).once('value'); | |
let firebaseJSON = await firebaseReq.val(); | |
setProjectsData(firebaseJSON); | |
} | |
if (!projectsData.projects.placeholder) { | |
getProjects(); | |
} | |
}, [projectsData]) | |
return ( | |
... | |
<Route path="/projects"> | |
<Projects projectsData={projectsData}/> | |
</Route> | |
... | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment