Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-placeholder

buildo128.6kISC4.1.0TypeScript support: included

A React component to easily replicate your page with nice placeholders while the content is loading

react, react-component, placeholder, filler, loading, paragraph

readme

React Placeholder

A React component to easily replicate your page with nice placeholders while the content is loading. You can use a placeholder from the default set, or pass your own!

image

import ReactPlaceholder from 'react-placeholder';
import "react-placeholder/lib/reactPlaceholder.css";

React.renderComponent(
  <div>
    <ReactPlaceholder type='media' rows={7} ready={this.state.ready}>
      <MyComponent />
    </ReactPlaceholder>
  </div>,
  document.body);

Live Demo

Install

npm install --save react-placeholder

Props

children:              ReactNode;
ready:                 boolean;
delay?:                number;
firstLaunchOnly?:      boolean;
showLoadingAnimation?: boolean;
type?:                 'text' | 'media' | 'textRow' | 'rect' | 'round';
rows?:                 number;
color?:                string;
customPlaceholder?:    ReactElement;
className?:            string;
style?:                CSSProperties;

The default props will render a text placeholder with 3 rows and the color #CDCDCD.

Customization

If the built-in set of placeholders is not enough, you can pass you own through the prop "customPlaceholder"

<ReactPlaceholder ready={this.state.ready} customPlaceholder={<MyCustomPlaceholder />}>
  <MyComponent />
</ReactPlaceholder>

You can also import the built-in placeholders directly. This might be useful to use them to create your own customized placeholder:

import {TextBlock, MediaBlock, TextRow, RectShape, RoundShape} from 'react-placeholder/lib/placeholders';

const awesomePlaceholder = (
  <div className='my-awesome-placeholder'>
    <RectShape color='blue' style={{width: 30, height: 80}}/>
    <TextBlock rows={7} color='yellow'/>
  </div>
);

<ReactPlaceholder ready={this.state.ready} customPlaceholder={awesomePlaceholder}>
  <MyComponent />
</ReactPlaceholder>

Delay

You can pass an optional delay prop which specifies the time (in milliseconds) react-placeholder should wait before displaying the placeholder element. This is useful if you want to show a placeholder for slower connections while avoiding a brief "flash" on faster connections.

Note that this delay will not affect the initial render, only subsequent "ready" state changes. Setting the firstLaunchOnly prop to true will also disable this feature.

Animation

react-placeholder already comes with one default pulse animation to better tell the user that the page is loading. The animation is defined in a separate CSS file so, in order to enable it, you should import that style in your project like this:

import 'react-placeholder/lib/reactPlaceholder.css';

Once you've done this, you can simply pass the boolean prop showLoadingAnimation to tell ReactPlaceholder to animate itself:

import 'react-placeholder/lib/reactPlaceholder.css';

<ReactPlaceholder showLoadingAnimation ready={this.state.ready} type="media" rows={5}>
  <p>This is a Test.</p>
</ReactPlaceholder>

Style

you can style the placeholder by passing className or style or by using the built-in classes:

"text-block", "media-block", "text-row", "rect-shape", "round-shape".

changelog

Change Log

v4.1.0 (2021-02-05)

Full Changelog

New features:

  • Problem with React 17 and npm version 7.5.1 on mac osx #95
  • [Question] CSS Import #94
  • type CustomPlaceholderProps showLoadingAnimation is undefined instead of boolean #90
  • v3.0.2 TypeScript error about missing properties #82
  • Do children and ready really have to be required props? #79

v4.0.3 (2020-06-11)

Full Changelog

v4.0.2 (2020-06-01)

Full Changelog

v4.0.1 (2020-03-13)

Full Changelog

New features:

  • TextRow/TextBlock ignores lineSpacing is equal to 0 #86
  • Is this package still maintained? #84

v4.0.0 (2020-02-29)

Full Changelog

Breaking:

  • Warning: componentWillReceiveProps has been renamed, and is not recommended for use. #83

v3.0.2 (2019-02-21)

Full Changelog

New features:

  • ReactPlaceholder text component doesn't override the width property #78
  • [Typings] Can't assign Element to customPlaceholder #75

v3.0.1 (2018-05-08)

Full Changelog

Fixes (bugs & defects):

  • Removed CSS? #72

v3.0.0 (2018-05-04)

Full Changelog

Breaking:

  • Refactor in TypeScript #69

New features:

  • index.d.ts missing 'style' property #67

v2.0.0 (2017-12-20)

Full Changelog

Breaking:

  • Array.apply not support ie8 in TextBlock even if I add the polyfill (again) #65

v1.0.10 (2017-12-15)

Full Changelog

Fixes (bugs & defects):

  • Array.apply not support ie8 in TextBlock even if I'm add the polyfill #62

New features:

  • TextBlock: make widths overridable #59

v1.0.9 (2017-11-28)

Full Changelog

New features:

  • Bug with delay when the component is already mounted #54

v1.0.8 (2017-10-25)

Full Changelog

New features:

  • Add "delay" prop to show the placeholder for a minimum time #49
  • React 16 warning message #46

v1.0.7 (2017-10-16)

Full Changelog

New features:

  • error in ready #44

v1.0.6 (2017-08-03)

Full Changelog

Fixes (bugs & defects):

  • @types/react > 33 complains #41
  • Animations not working with custom placeholders. #34

New features:

  • Action required: Greenkeeper could not be activated 🚨 #39
  • Action required: Greenkeeper could not be activated 🚨 #38

v1.0.5 (2017-06-26)

Full Changelog

Fixes (bugs & defects):

  • Typo in CSS selector for react-shape animation #33

v1.0.4 (2017-06-01)

Full Changelog

Fixes (bugs & defects):

  • Update typings to make lineSpacing prop optional #32

v1.0.3 (2017-05-31)

Full Changelog

New features:

  • animation support #27

Fixes (bugs & defects):

  • Rectangle placeholder without className sets class to undefined #24

v1.0.2 (2017-04-25)

Full Changelog

New features:

  • Add React 15.5 compatibility #22

v1.0.1 (2017-04-03)

Full Changelog

New features:

  • replace lodash.omit with ES6 destructuring #21

v1.0.0 (2017-03-23)

Full Changelog

Fixes (bugs & defects):

  • lodash and classnames should be deps, not devDeps #13

Breaking:

  • Use relative heights #10

v0.0.3 (2016-12-29)

Full Changelog

Fixes (bugs & defects):

  • package is currently broken #6

v0.0.2 (2016-11-08)

New features:

  • Replace react.createClass with ES6 class #3