Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
React and React Native

You're reading from   React and React Native Build cross-platform JavaScript apps with native power for mobile, web and desktop

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781786465658
Length 500 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Adam Boduch Adam Boduch
Author Profile Icon Adam Boduch
Adam Boduch
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Why React? 2. Rendering with JSX FREE CHAPTER 3. Understanding Properties and State 4. Event Handling – The React Way 5. Crafting Reusable Components 6. The React Component Lifecycle 7. Validating Component Properties 8. Extending Components 9. Handling Navigation with Routes 10. Server-Side React Components 11. Mobile-First React Components 12. Why React Native? 13. Kickstarting React Native Projects 14. Building Responsive Layouts with Flexbox 15. Navigating Between Screens 16. Rendering Item Lists 17. Showing Progress 18. Geolocation and Maps 19. Collecting User Input 20. Alerts, Notifications, and Confirmation 21. Responding to User Gestures 22. Controlling Image Display 23. Going Offline 24. Handling Application State 25. Why Relay and GraphQL? 26. Building a Relay React App

Declarative data dependencies

Relay uses the term colocation to describe declarative data dependencies that live beside the component that uses the data. This means that we don't have to go digging around for action creator functions that actually get the component data that is scattered across several modules. With colocation, we can see exactly what the component needs.

Let's get a taste of what this looks like. If you want to display the first and last name of a user, you need to tell Relay that your component needs this data. Then, you can rest assured that the data will always be there for your component. Here's an example:

const User = ({ first, last }) => ( 
  <section> 
    <p>{first}</p> 
    <p>{last}</p> 
  </section> 
); 
 
const UserContainer = Relay.createContainer(User, { 
  fragments: { 
    user: () => Relay.QL` 
      fragment on User { 
        first, 
        last, 
     } 
    `, 
  }, 
}); 

We have two components...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image