Last active
March 19, 2019 14:52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react' | |
import { useStore, useActions } from '../store' | |
function Stocks () { | |
// stocks is destructured from the store object for convenience | |
const { stocks } = useStore() | |
const actions = useActions() | |
// calls the API on component mount | |
useEffect(() => { | |
actions.stocks.fetchStocks() | |
}, []) | |
return ( | |
<div> | |
<ul> | |
{stocks.data && stocks.data.map(stock => ( | |
<li key={stock.id}>{stock.title}</li> | |
))} | |
</ul> | |
<button onClick={actions.stocks.fetchStocks}>Refresh stocks</button> | |
</div> | |
) | |
} | |
export default Stocks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment