- Let's start by opening the photos/reducer.js file and importing all of the action types we defined in the previous recipe, as follows:
import { FETCH_PHOTOS, ADD_PHOTO, REMOVE_PHOTO} from './actions';
- We'll define an initial state object for the state in this reducer. It has a photos property initialized to an empty array for the currently loaded photos, as follows:
const initialState = () => return { photos: []};
- We can now define the reducer function. It'll receive two parameters, the current state and the action that has been dispatched, as follows:
export default (state = initialState, action) => { // Defined in next steps
}
React Native components can also have a state object, but that is an entirely separate ...