Download netflix-clone-using-react/src/hooks/use-content.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 757 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/hooks/use-content.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/hooks/use-content.js
-
curl -L -o use-content.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/netflix-clone-using-react/src/hooks/use-content.js
757 Bytes
| import { useEffect, useState, useContext } from 'react'; | |
| import { FirebaseContext } from '../context/firebase'; | |
| export default function useContent(target) { | |
| const [content, setContent] = useState([]); | |
| const { firebase } = useContext(FirebaseContext); | |
| useEffect(() => { | |
| firebase | |
| .firestore().collection(target) | |
| .get().then((snapshot) => { | |
| const allContent = snapshot.docs.map((contentObj) => ({ | |
| ...contentObj.data(), | |
| docId: contentObj.id, | |
| })); | |
| setContent(allContent); | |
| }) | |
| .catch((error) => { | |
| console.log(error.message); | |
| }); | |
| }, []); | |
| return { [target]: content }; | |
| } |