import AnecdoteForm from './components/AnecdoteForm' import Notification from './components/Notification' import { useContext } from 'react' import { NotifContext } from './NotifReducer' import { useQuery, useMutation, useQueryClient } from 'react-query' import { getAnecdotes, updateAnecdote } from './requests' const App = () => { const queryClient = useQueryClient() const result = useQuery('anecdotes', getAnecdotes, { retry: 1}) const updateVoteMutation = useMutation(updateAnecdote, { onSuccess: () => { const anecdotes = queryClient.getQueryData('anecdotes') queryClient.invalidateQueries('anecdotes') } }) const [notif, notifDispatch] = useContext(NotifContext) if ( result.status === 'loading' ) { return
Loading data
} if (result.status === 'error') { return
Anecdote Service is unavailable due to problems in server
} const handleVote = (anecdote) => { updateVoteMutation.mutate(anecdote) notifDispatch({ type: 'SET', payload: `Voted Anecdote '${anecdote.content}'`}) setTimeout(() => { notifDispatch({ type: 'CLEAR'}) }, 5000); } const anecdotes = result.data return (

Anecdote App

{anecdotes.map(anecdote =>
{anecdote.content}
Has {anecdote.votes} Votes  
)}
) } export default App