I have a react component that will create a new document on mounting
const CreateGame: React.FunctionComponent<ICreateGameProps> = (props) => {
const gamesRef = useFirestore()
.collection('Games')
const [newGameId, setNewGameId] = useState('')
useEffect(() => {
const newGame: IGameDoc = {
playerTurn: 'x',
secondPlayerJoined: false,
gameState: {
rowOne: [null, null, null],
rowTwo: [null, null, null],
rowThree: [null, null, null]
}
}
gamesRef.add(newGame)
.then(docRef => setNewGameId(docRef.id))
return () => {
gamesRef.doc(newGameId).delete()
}
}, [])
however, as soon as the component unmounts again, I would like to delete that same document again, hence I have the cleanup function in my useEffect hook
return () => {
gamesRef.doc(newGameId).delete()
}
This does not work however. Does anyone know why?