react-x-render

3.0.0 • Public • Published

react-x-render

npm npm npm

Render React components conditionally using if and unless.

Getting Started

Install react-x-render using yarn:

yarn add react-x-render

Usage

import React from 'react';
import PropTypes from 'prop-types';
import {Text, View} from 'react-native';
import Render from 'react-x-render';
 
 
class HomePage extends React.Component {
 
  // --------------------------------------------------
  // Props
  // --------------------------------------------------
  static propTypes = {
    user: PropTypes.object.isRequired,
  };
 
  static defaultProps = {
  };
 
  // --------------------------------------------------
  // Render
  // --------------------------------------------------
  render() {
    const {user} = this.props;
 
    return (
      <View>
        <Render if={user.getIsActivated()}>
          <Text>{`Hi ${user.getName()}`}</Text>
        </Render>
        <View>
          ...
        </View>
        <Render unless={user.getIsDisabled()}>
          <Text>{`Receive $1,000,000 for free?`}</Text>
        </Render>
      </View>
    );
  }
 
}

Props

Prop Type Required Description
if boolean no If this is true, it will render the child.
unless boolean no If this is false, it will render the child.

Contributing

If you have any ideas on how this module could be better, create an Issue or submit a PR.

Package Sidebar

Install

npm i react-x-render

Weekly Downloads

1

Version

3.0.0

License

MIT

Unpacked Size

4.82 kB

Total Files

4

Last publish

Collaborators

  • negativetwelve