O'Reilly logo

React and React Native - Second Edition by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fetching component data

When your components are initialized you'll want to populate their state or properties. Otherwise, the component won't have anything to render other than its skeleton markup. For instance, let's say you want to render the following user list component:

import React from 'react';import { Map } from 'immutable';// This component displays the passed-in "error"// property as bold text. If it's null, then// nothing is rendered.const ErrorMessage = ({ error }) =>  Map([[null, null]]).get(error, <strong>{error}</strong>);// This component displays the passed-in "loading"// property as italic text. If it's null, then// nothing is rendered.const LoadingMessage = ({ loading }) => Map([[null, null]]).get(loading, <em>{loading}</em>); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required