October 2019
Intermediate to advanced
426 pages
11h 49m
English
We are now going to use our backend server to request the posts array, instead of hardcoding it as the default value for the postsReducer.
Let's implement requesting posts using an Effect Hook and a Reducer Hook:
const defaultPosts = [ { title: 'React Hooks', content: 'The greatest thing since sliced bread!', author: 'Daniel Bugl' }, { title: 'Using React Fragments', content: 'Keeping the DOM tree clean!', author: 'Daniel Bugl' }]
const [ state, dispatch ] = useReducer(appReducer, { user: '', posts: [] })
Read now
Unlock full access