Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created June 9, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshallmurphy/e9e1b79fe19b1710c22d2a749546d97d to your computer and use it in GitHub Desktop.
Save marshallmurphy/e9e1b79fe19b1710c22d2a749546d97d to your computer and use it in GitHub Desktop.
// App.js
// import the useEffect React hook
import React, { useEffect } from 'react'
// import the useDispatch Redux hook
import { useDispatch, useSelector } from 'react-redux'
// import our fetchRecipes thunk
import { fetchRecipes, recipesSelector } from './slices/recipes'
const App = () => {
// initialize the redux hook
const dispatch = useDispatch()
const { recipes, loading, hasErrors } = useSelector(recipesSelector)
// dispatch our thunk when component first mounts
useEffect(() => {
dispatch(fetchRecipes())
}, [dispatch])
return (
<section>
<h1>Recipes</h1>
</section>
)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment