Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.


    Add a Clear All Complete Button to the Footer with React Native TouchableOpacity

    Jason BrownJason Brown

    In this lesson we'll add a button to the footer that will clear all completed items. We'll use TouchableOpacity and we'll examine how flex space-around property works.

    react-nativeReact Native
    0.35 - 0.37


    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    00:00 We'll start by rendering a TouchableOpacity. Inside of there, we'll create a text element and say ClearCompleted. Now if we go over and we refresh, you can see that we have a ClearCompleted button rendering and there's space around all of the items. Now we'll go add an onPress to our TouchableOpacity and say this.props.onClearCompleted.

    00:23 Now, we'll switch back to our app and we'll add a handle ClearCompleted to be a function. Go ahead and bind this, this.handleClearCompleted = this.handleClearCompleted.bind(this). Now, we'll type const newItems = filterItems active, so we'll filter our items for only the active items, which will remove our completed items. We'll then say this.setSource and give it our new items, so we'll replace our array of items.

    01:04 We'll also filter items, this.state.filter and apply the filter to the new, the only active items. Now, we'll pass this into our footer. We'll say onClearCompleted = this.handleClearCompleted. When we go and we refresh our emulator, we can add an item, add another, you can toggle one of these to complete and click ClearCompleted and see that it disappeared.