7-3. Feed Component

Feedcomponent's roleRead data from contract:
getFeedmethodSave data to store:
setFeedactionShow data in component:
Feedcomponent
1) Feed component's role
Feed component's roleIn chapter 4. Write Klaystagram Smart Contract, we wrote PhotoData struct, and located it inside _photoList mapping. Feed component's role is as follows: 1. Read PhotoData via calling Klaystagram contract method (redux/actions/photos.js) 2. Show PhotoData(feed) with its owner information (components/Feed.js)
2) Read data from contract: getPhoto method
getPhoto methodCall contract method:
getTotalPhotoCount()If there are zero photos, call
setFeedaction with an empty array.Call contract method:
getPhoto(id)If there are photos, get each photo data as a promise and push it in the feed array. When all promises have resolved, return the feed array.
Call redux action:
setFeed(feed)Get resolved feed array and save it to redux store.
3) Save data to store: setFeed action
setFeed actionAfter we successfully fetch photo data (feed) from the Klaystagram contract, we call setFeed(feed) action. This action takes the photo data as a payload and saves it in a redux store.
4) Show data in component: Feed component
Feed componentAt the first time, you can only see the text "No photo :D" because there is no photo data in contract yet. Let's make a UploadPhoto component to send photo data to contract!
Last updated