import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';

/**
 * Renders a cell that displays a string/number value within
 * a react-native `Text` component.
 *
 * @param {string|number} value The value to render in cell
 */
const Cell = React.memo(({ value }) => {
  console.log(`- Cell: ${value}`);
  return (
    <View style={defaultStyles.cell}>
      <Text>{value}</Text>
    </View>
  );
});

Cell.propTypes = {
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

Cell.defaultProps = {
  value: '',
};

const defaultStyles = StyleSheet.create({
  cell: {
    flex: 1,
    backgroundColor: 'yellow',
    justifyContent: 'center',
  },
});

export default Cell;

/* eslint-disable react/forbid-prop-types */
import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
import { getAdjustedStyle } from './utilities';

/**
 * Renders a cell that displays a string/number value within
 * a react-native `Text` component.
 *
 * @param {string|number} value     The value to render in cell
 * @param {Object}        viewStyle Style object for the containing View
 * @param {Object}        textStyle Style object for the inner Text
 */
const Cell = React.memo(({ value, textStyle, viewStyle, width, isLastCell }) => {
  console.log(`- Cell: ${value}`);

  const internalViewStyle = getAdjustedStyle(viewStyle, width, isLastCell);

  return (
    <View style={internalViewStyle}>
      <Text style={textStyle}>{value}</Text>
    </View>
  );
});

const defaultStyles = StyleSheet.create({
  viewStyle: {},
  textStyle: {},
});

Cell.propTypes = {
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  textStyle: PropTypes.object,
  viewStyle: PropTypes.object,
  width: PropTypes.number,
  isLastCell: PropTypes.bool,
};

Cell.defaultProps = {
  value: '',
  textStyle: defaultStyles.textStyle,
  viewStyle: defaultStyles.viewStyle,
  width: 0,
  isLastCell: 0,
};

export default Cell;

Add new props to Cell component