Skip to content

Instantly share code, notes, and snippets.

@cvega21
Created August 24, 2021 04:39
Show Gist options
  • Save cvega21/a6721eb351d9bf7dce2eaa28fa7e88ba to your computer and use it in GitHub Desktop.
Save cvega21/a6721eb351d9bf7dce2eaa28fa7e88ba to your computer and use it in GitHub Desktop.
Keep portfolio data as app-level state
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